Middle+
What happens in INNER JOIN if one row on the left matches multiple rows on the right?
sobes.tech AI
Answer from AI
In the case of INNER JOIN, if one row from the left table corresponds to multiple rows from the right, the result will be multiple rows — each combination of the left row with each matching right row. That is, for each row on the left, new rows are created in the result, equal to the number of matches on the right.
Example:
-- Table A
id | name
1 | Alice
-- Table B
id | hobby
1 | Chess
1 | Painting
SELECT A.name, B.hobby FROM A INNER JOIN B ON A.id = B.id;
Result:
| name | hobby |
|---|---|
| Alice | Chess |
| Alice | Painting |
Thus, INNER JOIN expands the rows on the left to all corresponding rows on the right.