本文介绍了在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

推荐答案


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


这篇关于在SQL Server 2005中使用嵌套联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 12:35