62,046
社区成员
发帖
与我相关
我的任务
分享
select 表1.* from 表1 inner join 表2 on 表1.id=表2.id and 表2.age=18
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
/*
id name
----------- -----------
1 2
1 3
1 4
2 2
2 3
2 4
3 1
*/
declare @表2 table (id int,age int)
insert into @表2
select 1,18 union all
select 3,18
select * from @表2
/*
id age
----------- -----------
1 18
3 18
*/
select a.* from @表1 a right join @表2 b on a.id=b.id
/*
id name
----------- -----------
1 2
1 3
1 4
3 1
*/
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