How to find duplicate names in a table

I have a table that shows the names of people and the name of the post. names are sometimes repeated. I need to compare if two people have the same name and the same address than I only have one entry from them.

Table: Data_Excel Name: P_Name Address: P_Address City: P_city 
+6
source share
2 answers

To find duplicates, you can:

 SELECT P_name, P_Address, P_city FROM Data_Excel GROUP BY P_Name, P_Address, P_city HAVING COUNT(*) > 1; 

To remove duplicates, you can do:

 DELETE FROM Data_Excel WHERE rowid NOT IN ( SELECT MIN(rowid) FROM Data_Excel GROUP BY P_Name, P_Address, P_city ); 

To insert Person into a table, you must:

 INSERT INTO Person(id,name) SELECT (SELECT MAX(id)+1 FROM Person),P_Name FROM Data_Excel WHERE P_Name NOT IN (SELECT name FROM Person) 
+9
source
 SELECT P_Name,P_Address,count(*) FROM Data_Excel GROUP BY P_Name,P_Address HAVING count(*) > 1; 

This will give you entries with the same P_Name and P_Address .

+2
source

Source: https://habr.com/ru/post/958471/


All Articles