MySQL 删除与分组依据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6296102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:12:55 来源:igfitidea点击:
MySQL Delete with Group By
提问by Tom
I am running a query successfully using in MySQL 5.5
我在 MySQL 5.5 中成功运行查询
SELECT columnA
FROM
table
GROUP BY
columnA
HAVING
count(*) > 1
However, I need to run this same query using DELETE and I'm a little unsure how to delete ? i.e. the returned results should be deleted ?
但是,我需要使用 DELETE 运行相同的查询,但我有点不确定如何删除?即返回的结果应该被删除?
Any ideas ?
有任何想法吗 ?
回答by Denis de Bernardy
Place it in a subquery:
将其放在子查询中:
delete from table
where columnA in (
select columnA
from (
select columnA
from YourTable
group by columnA
having count(*) > 1
) t
)
回答by GolezTrol
delete from YourTable
where
YourTable.columnA
in
(select columnA
from
YourTable
group by
column A
having
count(*) > 1)