MySQL 删除与分组依据

MySQL Delete with Group By(MySQL 删除与分组依据)

本文介绍了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  
)

这篇关于MySQL 删除与分组依据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:MySQL 删除与分组依据

基础教程推荐