English 中文(简体)
页: 1 服务器加入Join声明的条件吗?
原标题:SQL Server join with condition in the Join statement?
  • 时间:2011-11-16 15:29:23
  •  标签:
  • sql-server

我很想知道:

select * 
from Table1 T1 
left join Table1 T2 on T1.id = T2.id + 1 and (T2.id > 3) 

<>

select * 
from Table1 T1 
left join Table1 T2 on T1.id = T2.id + 1 
where (T2.id > 3)
最佳回答

差异很大。

select * from Table1 T1 left join  Table1 T2 on T1.id=T2.id+1     where    (T2>3 

条款在哪些地方将左边改为内 join,因为该条款不允许从左边返回无效价值。 这意味着将排除左边会合谋记录的所有各行,因为退款的无效价值与3,并丢弃了行(这与使其成为内心结合具有同等效力)

第一份说明将过滤器纳入:

select * from Table1 T1 left join  Table1 T2 on T1.id=T2.id+1     and     (T2>3)  

This means it will take effect and filter the rows that can be joined to using the left join, but this will not cause rows to be discarded when the left join fails to find a matching row.

问题回答

In an INNER JOIN it doesn t matter where yuo put the condition.
It only makes a difference in a LEFT JOIN or RIGHT JOIN.

一段时间前,我就类似问题作了详细回答,解释了服务器在你两个案件中的每一个案件中都有所不同。

You can check it out here:
What is the difference in these two queries as getting two different result set?





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签