I am trying to join the data from three different tables into a single view in SQL. The relationship is as follows Parent -> Child 1 and Parent -> Child 2. Child 1 and Child 2 do not have any relationship among them. (See image below)
I tried using a left join and it ends up in the relationship Parent -> Child 1 -> Child 2.
Are you sure you are joining child2 to the parent table?
SELECT *
FROM Parent p
JOIN Child1 c1 on p.colA = c1.colA
JOIN Child2 c2 on p.colB = c2.colB
The idea is the following and depending which set you are after you change the joins ( left, inner, right in combination with where clauses eg WHERE c2.b is null). It would be much better to display sample data and desire output instead of a generic venn.
select * from Parent P
left join Child1 c1
on p.A=c1.A
left join Child2 c2
on p.B=c2.B
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.