I have a table having person names address and job title. the names are repeating sometimes. I have to compare if two people have the same name and same address than i have to keep only 1 record of them.
Table: Data_Excel
Name: P_Name
Address: P_Address
City: P_city
To find the duplicates you can do:
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 could 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 in Person table you would do:
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)
SELECT P_Name,P_Address,count(*)
FROM Data_Excel
GROUP BY P_Name,P_Address
HAVING count(*) > 1;
This will give you the records with same P_Name
& P_Address
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With