cbrune
asked on
How to Join multiple columns that reference themselves
I have table A{
id,
name
}
table B{
id,
aid,
bid,
cid
}
I need to go left joins on Table B to table A.. and show all table B and the references values for each row.
id,
name
}
table B{
id,
aid,
bid,
cid
}
I need to go left joins on Table B to table A.. and show all table B and the references values for each row.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why do you need a Left Join?
From what you write you want to start in table B and left join table A, it's very basically
Bye, Olaf.
Select B.*, A.name from B left join A on B.aid = A.id
Or am I missing anything in the meanings of aid,bid and cid in table B?Bye, Olaf.
But let's say table A is persons and table B is threads aid, bid and cid are all person IDs, eg
aid = QuestionByPersonID
bid = AnswerByPersonID
then you do two left joins:
aid = QuestionByPersonID
bid = AnswerByPersonID
then you do two left joins:
Select B.*,
aa.name as Asking,
ab.name as Answering
From B
Left Join A as aa on aa.id = B.aid
Left Join A as ab on ab.id = B.bid
Bye, Olaf.