Thursday, March 06, 2008

Oracle select duplicate record

Method1: Use oracle rowid, MIN or MAX function to do it.
SELECT rowid, column1, column2 FROM table1 t1 where t1.rowid>(SELECT MIN(t2.rowid) FROM table2 t2 where t2.column1=t1.column1 and t2.column2=t1.column2);

Method2: Use GROUP BY/HAVING function to do it.
SELECT count(*),column1, column2 FROM table1 GROUP BY column1, column2 having count(*) > 1;

No comments: