declare @a table(id int,[11] varchar(20))
insert into @a select 1,'eee'
insert into @a select 2,'www'
insert into @a select 3,'ddd'
insert into @a select 4,'eee'declare @b table(id int,aa varchar(20),bb int)
insert into @b select 1,'tt',5
insert into @b select 2,'rr',3
insert into @b select 5,'hh',1select
a.id,a.[11],b.aa,b.bb
from
@a a
left outer join
@b b
on
a.id=b.id and b.bb > 2
where
a.[11] ='eee' /*
id 11 aa bb
----------- -------------------- -------------------- -----------
1 eee tt 5
4 eee NULL NULL
*/
insert into @a select 1,'eee'
insert into @a select 2,'www'
insert into @a select 3,'ddd'
insert into @a select 4,'eee'declare @b table(id int,aa varchar(20),bb int)
insert into @b select 1,'tt',5
insert into @b select 2,'rr',3
insert into @b select 5,'hh',1select
a.id,a.[11],b.aa,b.bb
from
@a a
left outer join
@b b
on
a.id=b.id and b.bb > 2
where
a.[11] ='eee' /*
id 11 aa bb
----------- -------------------- -------------------- -----------
1 eee tt 5
4 eee NULL NULL
*/
on a.id=b.id
where a.11 ='eee'
and b.bb > 2
可以这样写吗,结果是什么?
是
1 eee tt 5
4 eee null null这样吗.
================================
不是
是
1 eee tt 5
要想得到你要的结果得这样
select a.id,a.11,b.aa,b.bb from a left outer join b
on a.id=b.id and b.bb > 2
where a.11 ='eee'
连接条件加 "on"
不能写在where 中