Junior — Middle
How to distinguish between an inner join and a left outer join when working with SQL queries?
sobes.tech AI
Answer from AI
In SQL, an INNER join returns only the rows that match the join condition in both tables.
A LEFT OUTER join returns all rows from the left table, and the matching rows from the right table. If there is no match, the right table's fields will be filled with NULL.
Example:
SELECT * FROM A INNER JOIN B ON A.id = B.a_id;
-- Returns only matching records
SELECT * FROM A LEFT JOIN B ON A.id = B.a_id;
-- Returns all records from A, and matching or NULL from B
Thus, the main difference is that an inner join filters only matching rows, while a left outer join preserves all rows from the left table.