select 1 from ta a where exists(select 1 from tb where a.id = id)
IF exists(select 1 from a join b on a.ID=b.ID) print '存在'
select * from a where exists(select * from b where a.id =b.id)
选出量表都有的数据 select * from A where ID in (select ID from B)
--存在 select * from A where 省份正 in (select 省份正 from B) --不存在 select * from A where 省份正 not in (select 省份正 from B)
select 1 from tb a where exists(select 1 from tb where a.id = id)id代表身份证。 tb代表表名(两个表哦)
伪代码:[前提]: 表table1, table2 列pid为身份证且两个表都存在if exists( select * from Table1 where pid in(select pid from Table2 )) begin print '存在' end else begin print '不存在' end
from ta a
where exists(select 1 from tb where a.id = id)
print '存在'
选出量表都有的数据
select * from A where ID in (select ID from B)
select * from A where 省份正 in (select 省份正 from B)
--不存在
select * from A where 省份正 not in (select 省份正 from B)
from tb a
where exists(select 1 from tb where a.id = id)id代表身份证。
tb代表表名(两个表哦)
表table1, table2
列pid为身份证且两个表都存在if exists( select * from Table1 where pid in(select pid from Table2 ))
begin
print '存在'
end
else
begin
print '不存在'
end