MySQL 删除与分组依据

2021-12-27 00:00:00 group-by mysql

我在 MySQL 5.5 中成功运行了一个查询

I am running a query successfully using in MySQL 5.5

SELECT columnA
FROM
  table
GROUP BY
  columnA
HAVING
  count(*) > 1

但是,我需要使用 DELETE 运行相同的查询,但我有点不确定如何删除?即返回的结果应该被删除吗?

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 from table 
where columnA in (
  select columnA
  from (
      select columnA
      from YourTable
      group by columnA
      having count(*) > 1
      ) t  
)

相关文章