I have a table with about 11 fields (columns), and I know for a fact that there are multiple repeating entries, but they are repeating only within few fields. What I want to do is that if two or more rows have identical ProviderName
and Address
in lowercase, and identical StateID
, then I want to delete those extra rows, and leave just one copy of it. I have something like this, but I have no idea how to complete it.
SET SQL_SAFE_UPDATEs=0;
DELETE FROM providers
WHERE LCASE(ProviderName), LCASE(Address), StateID;
UPDATE:
SET SQL_SAFE_UPDATES=0;
DELETE p1.*
FROM providers AS p1
JOIN providers AS p2
ON LCASE(p1.ProviderName) = LCASE(p2.ProviderName)
AND LCASE(p1.Address) = LCASE(p2.Address)
AND p1.Zip = p2.Zip
AND p1.StateID = p2.StateID
AND p1.ProviderId > p2.ProviderId