Re: [SQL ] 查詢table1,2某欄位相異的資料
※ 引述《iwhiori (玉米)》之銘言:
: select a.id from a where a.id not in (select b.id from b)
: From http://stackoverflow.com
還可以試試
select a.id from a
minus
select b.id from b
或 a left join b,找出 b 是 null 的:
select a.id from a
left join b on a.id = b.id
where b.id is null
not in 一般會建議寫 not exists, 大部份情況下速度會較佳
select a.id from a where
not exists (select 1 from b where b.id = a.id)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 183.179.61.91
※ 編輯: adrianshum 來自: 183.179.61.91 (12/31 00:27)
推
12/31 01:17, , 1F
12/31 01:17, 1F
推
12/31 10:22, , 2F
12/31 10:22, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):