假如我有两张表A:             B:
ID              ID
1                1
2                3现在我要选取出A表中有的记录而B表中没有的记录(此例中的2)该怎么写sql语句
如果要选取B中有的记录而A中没有的记录(此例中的3),该怎么写sql语句ps:我用的是sqlite数据库,两张表的字段都是一样的,我要对比出不一样的数据,然后重新写入到一张表中(能重新写入到B表中最好)

解决方案 »

  1.   

    select * from A
    except
    select * from B
    相同問題發一次,OK
      

  2.   


     select A.*
     from A
     left join B on A.ID=B.ID
     where B.ID is null
      

  3.   

    2楼的或者select * from a 
    where not exists(select 1 from b where a.id=b.id)
      

  4.   

    select * from A
    except
    select * from Borselect * from B
    except
    select * from A
      

  5.   


    ---也可以
    select * from a  
    where id not in(select id from b)