有两个表a b 都有一个id字段查询a表 如果a表的id在b表里存在就不查询出来select * from a where id not in (select id from b)
select * from a where id not in (select id from b)
select a.* from a where not exists(select 1 from b where id=a.id)
select * from a where not exists (select 1 from b where b.id=a.id)
select * from a where id not in (select id from b)--或select a.* from a left join b on a.id=b.id where b.id is null
select * from a where id not in (select id from b)
过路的。试问 select a.* from a where not exists(select 1 from b where id=a.id) 和 select * from a where id not in (select id from b)和 select a.* from a left join b on a.id=b.id where b.id is null 的性能
有两个表a b 都有一个id字段查询a表 如果a表的id在b表里存在就不查询出来--------------------------select * from a where not exists (select 1 from b where a.id=b.id)
过路的。试问 select a.* from a where not exists(select 1 from b where id=a.id) 和 select * from a where id not in (select id from b)和 select a.* from a left join b on a.id=b.id where b.id is null 的性能
--------------------- 這個要看表大小怎麼樣,如果 b 表小的話select a.* from a where not exists(select 1 from b where id=a.id) 和 select * from a where id not in (select id from b) 和 select a.* from a left join b on a.id=b.id where b.id is null都快, 如果 b 表大的話select * from a where id not in (select id from b)這個要慢
select * from a where id not in (select id from b)--或select a.*
from a left join b on a.id=b.id
where b.id is null
select a.* from a where not exists(select 1 from b where id=a.id)
和
select * from a where id not in (select id from b)和
select a.*
from a left join b on a.id=b.id
where b.id is null
的性能
where not exists (select 1 from b where a.id=b.id)
过路的。试问
select a.* from a where not exists(select 1 from b where id=a.id)
和
select * from a where id not in (select id from b)和
select a.*
from a left join b on a.id=b.id
where b.id is null
的性能
---------------------
這個要看表大小怎麼樣,如果 b 表小的話select a.* from a where not exists(select 1 from b where id=a.id)
和
select * from a where id not in (select id from b)
和
select a.*
from a left join b on a.id=b.id
where b.id is null都快,
如果 b 表大的話select * from a where id not in (select id from b)這個要慢