假设表A和表B都只有两个字段id,name
如何用一句SQL返回表A中存在的id,name结果集而在表B中不存在的id,name结果集

解决方案 »

  1.   

    try:
    select A.* from A left join B on A.id=B.id and A.name=B.name where B.id is null
      

  2.   


    select * from A
    where not exists(select top 1 0 from B where A.ID=B.ID)
      

  3.   

    select * from A AS A
    where not exists(select * from B where A.id=id and A.name=name)
      

  4.   

    select A.* from A left join B on A.id=B.id and A.name=B.name where B.id is nullselect * from A where not exists(select top 1 * from B where A.ID=B.ID)这两个都可以.
      

  5.   

    用CheckSum()最简单:select * from A where checksum(*) not in (select checksum(*) from B)
      

  6.   

    --前提:表中不能有text、ntext、image、cursor 数据类型的字段。用CheckSum()最简单:select * from A where checksum(*) not in (select checksum(*) from B)