What is the best way to delete the results of this selection from the table?
select id from taxon2 as a
where rank = 'No Taxon' and
(select count(*) from taxon2 as b
where a.id = b.parentid) = 0;
What is the best way to delete the results of this selection from the table?
select id from taxon2 as a
where rank = 'No Taxon' and
(select count(*) from taxon2 as b
where a.id = b.parentid) = 0;
Here is a solution with an OUTER JOIN
:
delete taxon2
from taxon2
left join taxon2 t2 on taxon2.id = t2.parentid
where t2.id is null;
And with 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)