本文介绍了使用分组方式删除MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySQL 5.5中成功运行查询

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

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



任何想法?

解决方案

把它放在一个子查询中:

pre $ $ code从表中删除
其中columnA in(
select columnA
from(
)从YourTable中选择columnA
$ b $ group by columnA
have count(*)> 1
)t


I am running a query successfully using in 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 ?

Any ideas ?

解决方案

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  
)

这篇关于使用分组方式删除MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 21:17