------解决方案-------------------- 找到孤儿 SELECT id FROM 表 where pid not in (select id from 表) 后删除对应的记录
需要在循环中进行,因为每次删除就可能有新的孤儿产生
大致这样:
<br />do {<br /> $rs = mysql_query('SELECT group_concat(id) FROM 表 where pid not in(select id from 表)');<br /> list($g) = mysql_fetch_row($rs);<br /> mysql_query("delete from 表 where id in (g)");<br />}where(mysql_affected_rows());<br />
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn