Similar to this Find duplicate records in MySQL, I want to pull out duplicate records in a MySQL database based on the value of a specific column.
To pull out the one with the highest ID, I can do:
SELECT MAX(id), name, address, no_purchase, count(id) as cnt FROM list
GROUP BY name, address HAVING cnt > 1
To pull out the one with the lowest ID, I can do:
SELECT MIN(id), name, address, no_purchase, count(id) as cnt FROM list
GROUP BY name, address HAVING cnt > 1
How can I pull it based on the highest no_purchase? When I do MAX(no_purchase), I didn't get the correct id.