从表中删除此选择结果的最佳方法是什么?
select id from taxon2 as a
where rank = 'No Taxon' and
(select count(*) from taxon2 as b
where a.id = b.parentid) = 0;
答案 0 :(得分:4)
以下是OUTER JOIN
:
delete taxon2
from taxon2
left join taxon2 t2 on taxon2.id = t2.parentid
where t2.id is null;
使用NOT EXISTS
:
delete from taxon2
where rank = 'No Taxon'
and not exists (
select 1
from (select * from taxon2) as b
where b.parentid=taxon2.id)