I have 3 tables that look like this: 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 a result, I want to get a joined table, where there will be zero values ββif there is no such data in any table. I want something to look like this:
ββββββ¦ββββββββ¦βββββββββββββ¦βββββββββ
β id β name β data1 β data2 β
β βββββ¬ββββββββ¬βββββββββββββ¬βββββββββ£
β 1 β name1 β some data1 β 456 β
β 1 β name1 β some data2 β 345 β
β 1 β name1 β some data3 β null β
ββββββ©ββββββββ©βββββββββββββ©βββββββββ
I canβt understand how I can do this. I tried with external connections, but the result was repeated. Maybe you can use something like a group 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 the result that I want, and how can I do this?
source
share