從表中刪除此選擇的結果的最佳方法是什麼?從mysql表中刪除選定的行
select id from taxon2 as a
where rank = 'No Taxon' and
(select count(*) from taxon2 as b
where a.id = b.parentid) = 0;
從表中刪除此選擇的結果的最佳方法是什麼?從mysql表中刪除選定的行
select id from taxon2 as a
where rank = 'No Taxon' and
(select count(*) from taxon2 as b
where a.id = b.parentid) = 0;
這裏是具有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)
的可能重複[如何從選擇MySQL中刪除?](http://stackoverflow.com/questions/4562787/how-to-delete-from-select-in-mysql) – 2014-09-24 04:58:29
不,那個答案在這裏不適用(或工作)。 a。和b。在選擇時需要不同的答案。 – xpda 2014-09-24 05:02:59