a、b兩表,找出id欄位中,存在a表,但是不存在b表的資料。
方法一:
使用 not in
select distinct 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
**:a、b兩表,找出id欄位中,存在a表,但是不存在b表的資料。
方法一:
使用 not in
select distinct 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
sql查詢 存在A表而不在B表中的id
a b兩表,找出id欄位中,存在a表,但是不存在b表的id a表 id b表 id 1 1 2 2 第一種 子查詢 select a.id from a where a.id not in select id from b 當b表中的id數值比較多的時候,那麼a 表中的id 會匹配b表中的每個id,...
SQL查詢 存在乙個表而不在另乙個表中的資料
a b兩表,找出id欄位中,存在a表,但是不存在b表的資料。a表總共13w資料,去重後大約3w條資料,b表有2w條資料,且b表的id欄位有索引。使用 not in 容易理解,效率低 執行時間為 1.395秒 a b兩表,找出id欄位中,存在a表,但是不存在b表的資料。a表總共13w資料,去重後大約3...
SQL查詢存在A表但不存在B表的資料
其中b表的b id欄位引用了a表的id欄位。現在有個查詢需求 給出已知的a表中的id,比如 id in 1,2,3 找出這些id在b表中沒有與之對應的記錄。比如說上面a表中的id 3這條記錄,b表中沒有b id與之對應 方式一.利用子查詢 select a.id from a a where a.i...