mysql删除重复元组保留最前一条

1 a
1 b
1 c
2 d

改为:
1 a
2 d

谢谢!!

# If you want to keep the row with the lowest id value:

DELETE FROM NAMES
 WHERE id NOT IN (SELECT * 
                    FROM (SELECT MIN(n.id)
                            FROM NAMES n
                        GROUP BY n.name) x)
# If you want the id value that is the highest:

DELETE FROM NAMES
 WHERE id NOT IN (SELECT * 
                    FROM (SELECT MAX(n.id)
                            FROM NAMES n
                        GROUP BY n.name) x)
 你这个没有主键,只能通过group by插入临时表,然后删除原表再写回才能实现。如果有了主键,那么可以用
delete from 表 where 主键 not in (select min(主键) from 表 group by 第二列)

group by就行了