liangcai
5/20/2016 - 12:59 PM

From http://stackoverflow.com/questions/4685173/delete-all-duplicate-rows-except-for-one-in-mysql sql删除重复值

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

DELETE n1 FROM names n1, names n2 WHERE n1.id > n2.id AND n1.name = n2.name
# 2) If you want to keep the row with the highest id value:

DELETE n1 FROM names n1, names n2 WHERE n1.id < n2.id AND n1.name = n2.name