Duplicity Removal

Duplicates bother all DBAs and analysts around the globe 🙂 When you have a key to differentiate them it is a piece of cake to get rid of them. However, if you don’t, it might get tricky. Check out the script below.

/****
 *
 *  In the group by section, place the list of columns 
 *  which will make the row unique.
 *
 *  -- if you want to get rid of all duplicates (you have to list down all columns here)
 *
 ****/
--DELETE /* remove duplicity */
SELECT * /* show duplicity */
FROM table_name
WHERE 1 = 1
AND ROWID NOT IN (
                  SELECT MIN(ROWID)
                  FROM table_name
                  WHERE 1 = 1
                  GROUP BY col1
                           ,col2 
                 )