找出A表中不等於B表的資料

2021-10-02 02:02:30 字數 471 閱讀 1057

a,b兩表,找到id欄位中,存在a表,但不存在b表的資料。

a表有13w資料,去重後3w。b表共2w資料 且有索引

方法一 not in 易於理解 速度慢

select

distinct a.id from a where id notin(

select id from b)

方法二 is not null 速度適中
select a.id from a left

join b on a.id=b.id on b.id is

notnull

方法三 過濾
select

*from a where

(select

count(1

)from b where a.id=b.id)

=0

三種方法第三種速度最快,如果業務允許可優選第三種。

oracle 中的不等於

oracle中不等於號問題 在oracle中,不等於號有幾種方式 例1 查詢age不等於23的資料 select fromtestwhereage 23 例2 查詢name不為lisi的資料 select fromtestwherename lisi 例3 null只能通過is null或者is n...

mysql中的不等於

乙個簡單地表資料 select from user where address 北京 select from user where address 北京 select from user where address 北京 select from user where address 北京 selec...

Oracle中的不等於號

今天碰到乙個oracle不等於的問題,最後搜尋了一下,發現下面資料,拿來跟大家分享一下 關於oracle中的不等於號 在oracle中,都是不等於號的意思。都可以使用。但是奇怪是的,我想拿出price不是180000的商品時 price是number型別的 select id,name from p...