How do I find duplicate values in a table in Oracle?
Another way:
SELECT *
FROM TABLE A
WHERE EXISTS (
SELECT 1 FROM TABLE
WHERE COLUMN_NAME = A.COLUMN_NAME
AND ROWID < A.ROWID
)
Works fine (quick enough) when there is index on column_name
. And it's better way to delete or update duplicate rows.
Aggregate the column by COUNT, then use a HAVING clause to find values that appear greater than one time.
SELECT column_name, COUNT(column_name)
FROM table_name
GROUP BY column_name
HAVING COUNT(column_name) > 1;
You don't need to even have the count in the returned columns if you don't need to know the actual number of duplicates. e.g.
SELECT column_name
FROM table
GROUP BY column_name
HAVING COUNT(*) > 1
Simplest I can think of:
select job_number, count(*)
from jobs
group by job_number
having count(*) > 1;