How do I left join other table but persist its root row?
Example
Table 1
ID | Column 1 | Column 2 |
---|---|---|
1 | Foo | bar |
Table 2
ID | table_id | Column 2 |
---|---|---|
1 | 1 | Foo bar |
2 | 1 | John Doe |
Expected result
ID | Column 1 | table_id | Column 2 |
---|---|---|---|
1 | foo | null | null (This row should persist because this is parent) |
1 | foo | 1 | Foo bar |
1 | foo | 1 | John Doe |
Query
SELECT table1.id, table1.column1, table2.table_id, table2.column2
FROM table1
LEFT JOIN table2 ON table1.id = table2.table_id