remove duplicates sql query results code example
Example 1: how to remove duplicate in sql
Distinct: helps to remove all the duplicate
records when retrieving the records from a table.
SELECT DISTINCT FIRST_NAME FROM VISITORS;
Example 2: query delete duplicates
DELETE FROM dups a USING (
SELECT MIN(ctid) as ctid, key
FROM dups
GROUP BY key HAVING COUNT(*) > 1
) b
WHERE a.key = b.key
AND a.ctid <> b.ctid