--建立测试环境
Create Table 表(c1 varchar(10),c2 varchar(10),c3 varchar(10))
--插入数据
insert into 表
select '1','1','a' union
select '1','2','b' union
select '1','3','c' union
select '2','1','d' union
select '2','2','e' union
select '2','3','f' union
select '2','4','g' unionselect * from 表
--测试语句
select a.*, b.c1 c4, b.c2 c5, b.c3 c6 from  表 a inner join 表 b
on a.c2=b.c2
where  a.c1 ='1' and b.c1 = '2'
 
--删除测试环境
Drop Table 表--结果
c1       c2       c3       c4        c5      c6
1 1 a 2 1 d
1 2 b 2 2 e
1 3 c 2 3 f

解决方案 »

  1.   

    select a.*,c4=b.c1,c5=b.c2,c6=b.c3
    from t1 a ,t1 b
    where a.c1=1 and b.c1=2 and a.c2=b.c2
      

  2.   

    --如果无对应的项显示为空select a.*,c4=b.c1,c5=b.c2,c6=b.c3
    from t1 a full join t1 b on a.c1=1 and b.c1=2 and a.c2=b.c2
      

  3.   

    select a.*,c4=b.c1,c5=b.c2,c6=b.c3
    from t1 a ,t1 b
    where a.c1=1 and b.c1=2 and a.c2=b.c2
      

  4.   

    select a.*,c4=b.c1,c5=b.c2,c6=b.c3 from t1 a 
    Inner Join t1 b
    On a.c1=1 and b.c1=2 and a.c2=b.c2