MYSQL查詢 存在乙個表而不在另乙個表中的資料

2022-05-17 01:39:08 字數 720 閱讀 9441

a、b兩表,找出id欄位中,存在a表,但是不存在b表的資料。a表總共13w資料,去重後大約3w條資料,b表有2w條資料,且b表的id欄位有索引。

使用 not in ,容易理解,效率低  ~執行時間為:1.395秒~

select distinct a.id from  a  where a.id not in (select id from b)

select a.id froma left join b on a.id=b.idwhere b.id is null

a left join b on a.id=b.id //只有left join再加上on關聯,才是left join
**

select * from  b 

where (select count(1) as num from a where a.id = b.id) = 0

$query = $query->leftjoin(

'=',

'product_skus.id')

->where('product_skus.sku_stage', '=', productskumodel::sku_stage_pending_pricing)

MYSQL查詢 存在乙個表而不在另乙個表中的資料

a b兩表,找出id欄位中,存在a表,但是不存在b表的資料。a表總共13w資料,去重後大約3w條資料,b表有2w條資料,且b表的id欄位有索引。使用 not in 容易理解,效率低 執行時間為 1.395秒...

MYSQL查詢 存在乙個表而不在另乙個表中的資料

a b兩表,找出id欄位中,存在a表,但是不存在b表的資料。a表總共13w資料,去重後大約3w條資料,b表有2w條資料,且b表的id欄位有索引。使用 not in 容易理解,效率低 執行時間為 1.395秒 select distinct a.id from a where a.id not in ...

MYSQL查詢 存在乙個表而不在另乙個表中的資料

a b兩表,找出id欄位中,存在a表,但是不存在b表的資料。a表總共13w資料,去重後大約3w條資料,b表有2w條資料,且b表的id欄位有索引。使用 not in 容易理解,效率低 執行時間為 1.395秒 1 select distinct a.id from a where a.id not i...