Complex query, many joins
I've been wrestling with this for a few hours and I'm hoping you can give me some fresh insight. I have 6 tables as f开发者_高级运维ollows:
- Table A
- Table B, which is a child of A (one-to-many)
- Table C, which is a child of B (one-to-many)
Table D, which is a another child of A (one-to-many)
Table E is another parent of D, in a one-to-[zero-or-one] relationship
- Table F, which is another child of E (one-to-many)
Basically I need to select a field from B where C = F.
I have tried with subqueries, joins, and a combination of both, but have not got too far. Any ideas would be appreciated.
With the information you've presented, how about
SELECT *
FROM A
INNER JOIN B ON B.AID = A.AID
INNER JOIN C ON C.BID = B.BID
INNER JOIN D ON D.AID = A.AID
INNER JOIN E ON E.DID = D.DID
INNER JOIN F ON F.EID = E.EID
WHERE C.Field = F.Field
If this is not what you need, you might want to post a small subset of data with the required results.
精彩评论