分享到: ------解决方案-------------------- 不用递归的话,这个问题我不会。希望楼下各大牛给出答案。 我特别想问一个问题:“在实际的应用中,是否有这种需求?项目经理不让你用递归?” 不以解决问题为目的的自寻烦恼都是耍流氓。。。哈哈。。。 ------解决方案-------------------- 找到孤儿 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