在SQL Server 2005中使用嵌套联接
问题描述:
亲爱的所有人,
我正在尝试在sql 2005中使用嵌套联接.
像这样的东西:
Dear All,
I am trying to use nested joins in sql 2005.
something like this :
SELECT *
FROM TABLE1
LEFT JOIN TABLE2
INNER JOIN TABLE3 ON TABLE2.ID = TABLE3.ID
ON TABLE1.ID = TABLE2.ID
但是它不起作用.
我读了一些我们可以通过这种方式使用嵌套连接的地方,但是我忘记了源代码.有人知道以这种方式使用嵌套联接吗?
任何帮助将不胜感激.
问候,
Gopal
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
答
请参阅讨论"
nested-inner-joins
see Discussion
nested-inner-joins
您以错误的方式编写查询.试试这个
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
<-您不能通过一个连接添加2个ON条件
正确的查询将是:
<-- 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