Reputation: 47
can anybody explain how this multiple joins works? Primary Key of A goes to Table B as foreign key while Primary key of B goes to C as foreign key. Thanks in advance.
Table A TABLE B (has fk of A) TBALE C (HAS FK OF B)
aid aname bid bname afk cid cname bfk
1 a 1 b 1 1 c 1
2 a2 2 b2 2 2 c2 1
select a.aname , b.bname , c.cname from A a
left join B b
on a.aid = b.afk
left join C c
on c.bfk = b.bid;
Upvotes: 1
Views: 295
Reputation: 2906
You will end up with the following result set:
a b c
a b c2
a2 b2 Null
You have no entry for the cname in the third record because there is no record in table c that has a bfk of 2.
Upvotes: 1