日期:2014-05-18 浏览次数:20392 次
declare @表1 table (id int,name int) insert into @表1 select 1,2 union all select 1,3 union all select 1,4 union all select 2,2 union all select 2,3 union all select 2,4 union all select 3,1 select * from @表1 declare @表2 table (id int,age int) insert into @表2 select 1,18 union all select 3,18 select * from @表2 select a.* from @表1 a right join @表2 b on a.id=b.id
------解决方案--------------------
select 表1.* from 表1 inner join 表2 on 表1.id=表2.id and 表2.age=18
------解决方案--------------------
楼主要两个1,3,因此需要左连接left join
------解决方案--------------------
SELECT * FROM 表1 where id in ( select id from 表2 where age ='18')
------解决方案--------------------
结贴吧
------解决方案--------------------
select 表1.id as id,name
from 表1 left outer join
(select id,age
from 表2
where age='条件') as 表3
on 表1.id = 表3.id