有这样一个查询的差异:

两张表如下:

语句在这里:

 1 create table #AA
 2 (
 3   ID int,
 4   Name nvarchar(50)
 5 )
 6 
 7 insert into #AA
 8 select 1,'项目1'
 9 union all
10 select 2,'项目2'
11 union all
12 select 3,'项目3'
13 union all
14 select 4,'项目4'
15 union all
16 select 5,'项目5'
17 
18 create table #BB
19 (
20   ID int,
21   ProjectID int,
22   Name nvarchar(50)
23 )
24 
25 insert into #BB
26 select 1,1,'绿化园林'
27 union all
28 select 2,2,'安装玻璃'
29 union all
30 select 3,3,'拉电线'
View Code

查询差异如下:

 

 条件放在left join ..on后面不会过滤掉左表的内容,对于右表,没有的内容会填充null。而如果条件放在where后面,则会过滤掉左表的内容。

 

posted on 2014-09-10 14:10  水语者9  阅读(1487)  评论(0编辑  收藏  举报