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)
精彩评论