在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这样的语句会把所有内容都挑出来
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这样的语句会把所有内容都挑出来
select *
from table1,table2
where
t1.col1 = t2.col1
and t1.col2 = t2.col2
and t1.col1='A' and t1.col2='C'
(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
from table1 t1,table2 t2
where
t1.col1 = t2.col1
and t1.col2 = t2.col2