注册 登录
编程论坛 SQL Server论坛

关于SQL,根据一个表的搜索结果,再搜索另一个表

piguan 发布于 2010-05-24 01:04, 711 次点击
SQL语句怎么写呢?
A表
  1     2  
——————
999     0
888     1
777     0

B表
 1      2
——————
AAA    999
BBB    888
CCC    777

即从A表中搜出A.2=0的999、777,再搜出B表中含999、777的行。
2 回复
#2
cnfarer2010-05-24 10:44
select * from B where [2] in (select [1] from A where [2]=0)
#3
luozuguo2010-05-24 15:33
select * from B inner join A on B.2=A.1
where exists(select A.1 from A where A.2=0)
1