Does swapping the tables change the result of a LEFT JOIN?
The query counts the rows produced by two LEFT JOIN operations: first with iv_t1 on the left, then with iv_t2 on the left. How many rows does each join return?
Predict the resultJOIN and row countsJuniorFrom interview write-ups: T-BankAnalystData EngineerBackendQA
Input data · iv_t1
| x |
|---|
| 1 |
| 1 |
| 2 |
| NULL |
Input data · iv_t2
| x |
|---|
| 1 |
| 2 |
| 2 |
| 3 |
| NULL |
Query
SELECT
(SELECT COUNT(*) FROM iv_t1 LEFT JOIN iv_t2 ON iv_t1.x = iv_t2.x) AS t1_left_t2,
(SELECT COUNT(*) FROM iv_t2 LEFT JOIN iv_t1 ON iv_t2.x = iv_t1.x) AS t2_left_t1