日期:2014-05-17 浏览次数:20643 次
--> 测试数据: @TableA
declare @TableA table (a1 int,a2 int,a3 varchar(1))
insert into @TableA
select 1,2,'a' union all
select 1,3,'b' union all
select 2,2,'c' union all
select 2,3,'d' union all
select 3,1,'e' union all
select 3,3,'f'
--> 测试数据: @TableB
declare @TableB table (b1 int,b2 int,b3 varchar(1))
insert into @TableB
select 1,2,'a' union all
select 1,3,'b' union all
select 2,2,'c' union all
select 2,3,'d' union all
select 3,1,'e' union all
select 3,3,'f'
select * from @TableA a inner join @TableB b
on a.a1='1' where b.b1='2'
/*
a1 a2 a3 b1 b2 b3
----------- ----------- ---- ----------- ----------- ----
1 2 a 2 2 c
1 3 b 2 2 c
1 2 a 2 3 d
1 3 b 2 3 d
*/