Right Join — SQL Technical Interview Questions & Answers
Right Join
Right Join
- RIGHT JOIN keeps all rows from the right table. It is LEFT JOIN with the tables swapped. Most teams write LEFT JOIN only, and put the ‘must keep’ table on the left.
- Know the name for MCQs. In code, prefer LEFT JOIN for readability.
- Trap: mixing LEFT and RIGHT in one query until nobody can draw it.
- On the example next to this theory: Right Join — jOIN combines rows using a match condition between tables.
Technical Interview Tip: RIGHT JOIN = LEFT JOIN with tables swapped. Prefer LEFT.
Code Examples for Right Join
Right Join — sample query
CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE orders (id INTEGER PRIMARY KEY, customer_id INTEGER, total INTEGER);
INSERT INTO customers VALUES (1, 'Asha'), (2, 'Ravi');
INSERT INTO orders VALUES (10, 1, 500), (11, 1, 200);
SELECT c.name, o.total
FROM customers c
JOIN orders o ON o.customer_id = c.id;Right Join — jOIN combines rows using a match condition between tables.
How to Explain Right Join to an Interviewer
RIGHT vs LEFT?
Which side is kept in full Swap tables to use only LEFT