我试图删除所有与在我的MyBB数据库中使用两次以上的ip相关的帐户。下面的代码用于"选择"这些用户。
SELECT * FROM `mybb_forumusers` WHERE `regip` IN (
SELECT `regip` FROM `mybb_forumusers`
GROUP BY `regip`
HAVING COUNT( `regip` ) > 2
)
但是,我不能成功地删除所有这些用户而不出现错误。我尝试了以下(和变化):
DELETE FROM `mybb_forumusers` WHERE `uid` IN (
SELECT `uid` FROM `mybb_forumusers` WHERE `regip`IN (
SELECT `regip` FROM `mybb_forumusers`
GROUP BY `regip`
HAVING COUNT( `regip` ) > 2
)
)
我建议使用join
:
DELETE fu
FROM `mybb_forumusers` fu JOIN
(SELECT `regip`
FROM `mybb_forumusers`
GROUP BY `regip`
HAVING COUNT( `regip` ) > 2
) fu2
ON fu2.regip = fu.regip;