判断一个表中记录在另一个表是否存在同一个数据库的SQL语句怎么写?

解决方案 »

  1.   

    select 1
    from ta a
    where exists(select 1 from tb where a.id = id)
      

  2.   

    IF exists(select 1 from a join b on a.ID=b.ID)
    print '存在'
      

  3.   

    select * from a where exists(select * from  b where a.id =b.id)
      

  4.   


    选出量表都有的数据
    select * from A where ID in (select ID from B)
      

  5.   

    --存在
    select * from A where 省份正 in (select 省份正 from B)
    --不存在
    select * from A where 省份正 not in (select 省份正 from B)
      

  6.   

    select 1 
    from tb a 
    where exists(select 1 from tb where a.id = id)id代表身份证。
    tb代表表名(两个表哦)
      

  7.   

    伪代码:[前提]:
    表table1, table2 
    列pid为身份证且两个表都存在if exists( select * from Table1 where pid in(select pid from Table2 ))
    begin
          print '存在'
    end
    else
    begin
          print '不存在'
    end
      

  8.   

    有没有循环,怎么会返回几个“存在”只要有相同记录,就会print “存在”