在SQL Server中table1
col1   col2
A      C
B      Dtable2
col1   col2
A      D
A      C
B      C
B      D我希望在table2中找到table1中的内容例如,table1中有 A,C,那么table2中也找到A,C我尝试用这种方法:
select * 
from table1,table2
where
t1.col1 = t2.col1
and t1.col2 = t2.col2这样的语句会把所有内容都挑出来

解决方案 »

  1.   


    select * 
    from table1,table2 
    where 
    t1.col1 = t2.col1 
    and t1.col2 = t2.col2 
    and t1.col1='A' and t1.col2='C'
      

  2.   

    SELECT * FROM TABLE2 WHERE CHECKSUM(*) IN(SELECT CHECKSUM(*) FROM TABLE1)
      

  3.   

    select * from table2 a where exists(select 1 from table1 where col1=a.col1 and col2=a.col2)
      

  4.   

    select * from table2 a where exists(select 1 from table1 b where a.col1 = b.col1 and a.col2 = b.col2)
      

  5.   

    select b.col1,b.col2 from table2 b left join table1 a on a.col1=b.col1 and a.col2=b.col2
      

  6.   

    如楼上,改成t1.*就可以了,不知你的意思是不是如下create table table1 
    (col1 sysname,
    col2 sysname)insert into table1
    select 'A',     'C' 
    union all
    select 'B', 'D' create table table2 
    (col1 sysname,
    col2 sysname)insert into table2
    select 'A',     'D' 
    union all
    select 'A',     'C' 
    union all
    select 'B', 'C' 
    union all
    select 'B', 'D' select * 
    from table1 t1,table2 t2 
    where 
    t1.col1 = t2.col1 
    and t1.col2 = t2.col2  
      

  7.   

    select t1.* 
    from table1 t1,table2 t2 
    where 
    t1.col1 = t2.col1 
    and t1.col2 = t2.col2