If a table is like this:
id | complains | zipcode
--------------------------
1 | drinking | 10000
2 | drinking | 10000
3 | wasting | 10000
4 | wasting | 10000
5 | wasting | 10000
6 | wasting | 10011
7 | wasting | 10011
I want to get just:
---------------
drinking 10000
wasting 10000
wasting 10011
---------------
How should I write a SQL query? I wrote like this, but update and select cannot be execute at same time in mySQL.
delete from table where id not in (select max(id) from table group by complains, zipcode)
You can use a subselect to trick MySQL: