Junior — Middle
What is the difference between an inner join and a right outer join in SQL?
sobes.tech AI
Answer from AI
In SQL, an inner join (INNER JOIN) and a right outer join (RIGHT OUTER JOIN) differ in which rows from the tables are included in the result.
-
INNER JOIN returns only those rows where there are matches in both tables based on the join condition.
-
RIGHT OUTER JOIN returns all rows from the right table and the matching rows from the left table. If there is no match for a row from the right table in the left table, the fields from the left table will be filled with NULL.
Example:
SELECT * FROM A INNER JOIN B ON A.id = B.a_id;
-- Returns only rows where A.id matches B.a_id
SELECT * FROM A RIGHT OUTER JOIN B ON A.id = B.a_id;
-- Returns all rows from B, even if there is no match in A