MySQL - 删除选择
MySQL - Delete a selection
我正在尝试删除与我的 MyBB 数据库中使用超过两次的 IP 关联的所有帐户。以下代码适用于 "select" 这些用户。
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;
我正在尝试删除与我的 MyBB 数据库中使用超过两次的 IP 关联的所有帐户。以下代码适用于 "select" 这些用户。
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;