开发者

MySQL Delete with Group By

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜