Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从mysql中的表中删除所选行_Mysql_Sql - Fatal编程技术网

从mysql中的表中删除所选行

从mysql中的表中删除所选行,mysql,sql,Mysql,Sql,从表中删除此选择结果的最佳方法是什么 select id from taxon2 as a where rank = 'No Taxon' and (select count(*) from taxon2 as b where a.id = b.parentid) = 0; 下面是一个带有外部联接的解决方案: delete taxon2 from taxon2 left join taxon2 t2 on taxon2.id = t2.parentid wh

从表中删除此选择结果的最佳方法是什么

select id from taxon2 as a 
   where rank = 'No Taxon' and 
   (select count(*) from taxon2 as b 
      where a.id = b.parentid) = 0;

下面是一个带有
外部联接的解决方案

delete taxon2 
from taxon2
  left join taxon2 t2 on taxon2.id = t2.parentid
where t2.id is null;
并且不存在

delete from taxon2
where rank = 'No Taxon' 
   and not exists (
      select 1
      from (select * from taxon2) as b 
      where b.parentid=taxon2.id)

可能重复的“否”,该答案在此处不适用(或不起作用)。a。和b。在选择中,您需要一个不同的答案。@xpda--很高兴这能有所帮助。现在我看到了您的
rdbms
,我还包括了一个
外部连接
解决方案。