开发者

MySQL Delete with Group By

开发者 https://www.devze.com 2023-03-11 23:19 出处:网络
I am running a query successfully using in MySQL 5.5 SELECT columnA FROM table GROUP BY columnA HAVING count(*) > 1

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 r开发者_开发问答esults 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  
)


delete from YourTable
where
  YourTable.columnA 
  in 
  (select columnA
  from
    YourTable
  group by
    column A
  having
    count(*) > 1)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号