从mysql表中删除选定的行
问题描述:
从表中删除此选择的结果的最佳方法是什么?从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://*.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