Answered by:
SQL Join

-
I have a Asset table and a project table associated with it , the project is associated with a county and so is the asset but project can be in couple of counties so we track the county for asset individually, so if i wanted to write a query which will show the DataAsset, Project , DataAsset County , Project County how do i go about it ? Usually i just do an inner join and when i do Counties.County i know its coming from the join but given there are two joins to county in this query i don't know how to approch this. Hope I could explain the issue i have included the diagram below if it helps.
Question
Answers
-
SELECT * FROM Project P INNER JOIN DataAssest DA ON P.apexID = DA.ID INNER JOIN Counties C ON DA.CountyID = C.ID INNER JOIN counties CP on P.CountyID = CP.ID
I see. Simply join county again from the project:
- Marked as answer by Nikhil_NK Wednesday, July 02, 2014 5:09 PM
All replies
-
Hi,
Can you clarify something: a project can have a county and a data asset, and a data asset can have a county. Can these counties ever be different?
If not, then you need not worry about the two joins to Counties. Just do the one from Project (or DataAsset).
Hope this helps,
-
-
-
-
SELECT * FROM Project P INNER JOIN DataAssest DA ON P.apexID = DA.ID INNER JOIN Counties C ON DA.CountyID = C.ID INNER JOIN counties CP on P.CountyID = CP.ID
I see. Simply join county again from the project:
- Marked as answer by Nikhil_NK Wednesday, July 02, 2014 5:09 PM
-