如何删除表中多个字段的重复项?(mysql)

如何删除表中多个字段的重复项?(mysql),mysql,Mysql,如果表格是这样的: id | complains | zipcode -------------------------- 1 | drinking | 10000 2 | drinking | 10000 3 | wasting | 10000 4 | wasting | 10000 5 | wasting | 10000 6 | wasting | 10011 7 | wasting | 10011 我只想得到: ------------

如果表格是这样的:

id | complains | zipcode
--------------------------
1  |  drinking |  10000
2  |  drinking |  10000
3  |  wasting  |  10000
4  |  wasting  |  10000
5  |  wasting  |  10000
6  |  wasting  |  10011
7  |  wasting  |  10011
我只想得到:

---------------
drinking  10000
wasting   10000
wasting   10011
---------------
我应该如何编写SQL查询?我是这样写的,但是在mySQL中更新和选择不能同时执行

delete from table where id not in (select max(id) from table group by complains, zipcode)

您可以使用子选择来欺骗MySQL:

delete from table 
where id not in 
(
     select * from (select max(id) from table group by complains, zipcode) x
)

为什么要删除行而不是只选择所需的数据呢?我创建了一个新表并解决了这个问题。谢谢!