文章出處

方法一(僅適用單個字段)
使用 not in ,容易理解,效率低

select A.ID from A where A.ID not in (select ID from B)

方法二(適用多個字段匹配)
使用 left join...on... , "B.ID isnull" 表示左連接之后在B.ID 字段為 null的記錄

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

方法三(適用多個字段匹配)

select * from B where (select count(1) as num from A where A.ID = B.ID) = 0

方法四(適用多個字段匹配)

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

 

同步發表于我的個人網站:http://www.zuowenjun.cn/post/2014/10/09/54.html


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()