作者adrianshum (Alien)
看板Database
标题Re: [SQL ] 查询table1,2某栏位相异的资料
时间Sat Dec 31 00:26:14 2011
※ 引述《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)
1F:推 TeemingVoid:推 Alien大大果然厉害! ^^ Exists那段很精采 12/31 01:17
2F:推 iwhiori:推!!精彩! 12/31 10:22