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

2022-01-24 00:01:58 字數 595 閱讀 6983

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

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秒 1 select distinct a.id from a where a.id not i...

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 ...