Sobes.tech
Junior

Can a LEFT JOIN return more rows than in the left table (for example, 12 instead of 10)?

sobes.tech AI

Answer from AI

Yes, LEFT JOIN can return more rows than in the left table.

This happens if one record from the left table matches multiple records in the right table. LEFT JOIN returns all rows from the left table and adds data from the right, duplicating the left table's rows for each match.

For example, if the left table has 10 rows, and for one of them, the right table has 3 matches, the final result will contain 12 rows (9 with one match each and 3 for the one with multiple matches).

Example:

SELECT a.id, b.value
FROM a
LEFT JOIN b ON a.id = b.a_id;

If a contains 10 rows, and for a.id = 5 there are 3 rows in b, the result will be 12 rows.

Can a LEFT JOIN return more rows than in the left… - sobes.tech