I have 3 tables looks like: Table1:
╔════╦═══════╗
║ id ║ name ║
╠════╬═══════╣
║ 1 ║ name1 ║
╚════╩═══════╝
Table2:
╔════╦════════════╗
║ id ║ data1 ║
╠════╬════════════╣
║ 1 ║ some data1 ║
║ 1 ║ some data2 ║
║ 1 ║ some data3 ║
╚════╩════════════╝
Table3:
╔════╦═══════╗
║ id ║ data2 ║
╠════╬═══════╣
║ 1 ║ 456 ║
║ 1 ║ 345 ║
╚════╩═══════╝
As result I want to get joined table where will be null values if there is no such data in some table. I want to get something looks like this:
╔════╦═══════╦════════════╦════════╗
║ id ║ name ║ data1 ║ data2 ║
╠════╬═══════╬════════════╬════════╣
║ 1 ║ name1 ║ some data1 ║ 456 ║
║ 1 ║ name1 ║ some data2 ║ 345 ║
║ 1 ║ name1 ║ some data3 ║ null ║
╚════╩═══════╩════════════╩════════╝
I can't figure out how can I do this. I was trying with outer joins but result have repeats. Maybe it is possible to use something like group by or other agregate function?
Now my code is:
SELECT * FROM Table1 t1
left outer join Table2 t2 on t1.id=t2.id
left outer join Table3 t3 on t1.id=t3.id
Is it possible to get result I want and how I can do this?