sql语句 如何判断A表中的a列数据是否在B表中的b列中存在

如题 A表中有a列 假设数据为1,2,3
B表中有b列 假设数据为2,3,4
现在需要判断a列中的数据在b列中存在

select A.a from A,B where A.a=B.b 最简单的判断。
用IN的话可能出错:select a from A where a IN(select b from B)
用exists如楼上所说~
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-04-21
--存在
select *
from A
where exists(select 1 from B where A.a = B.b)

--不存在
select *
from A
where not exists(select 1 from B where A.a = B.b)本回答被提问者和网友采纳
第2个回答  2009-06-03
SELECT a from A
WHERE a in (select b from B)
第3个回答  2009-06-03
用in语法
相似回答