Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting duplicates keeping the minimum ID

I have a persons table with duplicate person inserted with different id. I want to delete the person with duplicate names keeping only the person with the minimum ID. for e.G The record for Absalon with ID 18398 should remain and all the other duplicates are deleted.

enter image description here

like image 218
Mouzzam Hussain Avatar asked Jan 15 '14 09:01

Mouzzam Hussain


People also ask

How do I remove duplicate rows and keep the highest value only?

1. If you want to remove all duplicates but leave the highest ones, you can apply this formula =MAX(IF($A$2:$A$12=D2,$B$2:$B$12)), remember to press Shift + Ctrl + Enter keys. 2. In the above formulas, A2:A12 is the original list you need to remove duplicates from.

What happens when you use the Remove Duplicates option?

When you use the Remove Duplicates feature, the duplicate data will be permanently deleted. Before you delete the duplicates, it's a good idea to copy the original data to another worksheet so you don't accidentally lose any information. Select the range of cells that has duplicate values you want to remove.

How do I remove duplicates but leaving the lowest value in another column in Excel?

If you sort on col A and then descending by col C, you can then just select all columns and do Data > Remove duplicates.


1 Answers

DELETE FROM persons WHERE id NOT IN (SELECT MIN(id) FROM persons GROUP BY name)

like image 149
Alexander Avatar answered Oct 23 '22 03:10

Alexander