Click here to Skip to main content
15,905,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,

I am trying to use nested joins in sql 2005.

something like this :
SQL
SELECT *
FROM TABLE1
LEFT JOIN TABLE2
    INNER JOIN TABLE3 ON TABLE2.ID = TABLE3.ID
ON TABLE1.ID = TABLE2.ID


However it is not working.
I read it some where that we can use nested join in this way but i have forgotten the source. Does anybody know about using nested joins in this fashion?

Any help would be much appreciated.

Regards,
Gopal
Posted

see Discussion
nested-inner-joins
 
Share this answer
 
Comments
gopalgupta 23-Dec-11 2:24am    
i think the example is different to my question....
i doesn't state if i can use joins in the manner i am trying to ..
You have written query in wrong way. try this

SELECT *
FROM TABLE1
LEFT JOIN TABLE2  <-- Give "ON with condition" i.e. below "ON TABLE1.ID = TABLE2.ID"
    INNER JOIN TABLE3 ON TABLE2.ID = TABLE3.ID
ON TABLE1.ID = TABLE2.ID
<-- You can not add 2 ON condition with one join

Right Query will be :

SELECT *
FROM TABLE1
LEFT JOIN TABLE2  ON TABLE1.ID = TABLE2.ID
    INNER JOIN TABLE3 ON TABLE2.ID = TABLE3.ID
 
Share this answer
 
v2
Comments
gopalgupta 23-Dec-11 6:32am    
thnx .... but we can write a nested join like my example ...
i resolved it and its working fine ....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900