S
S
shellnet2021-06-23 09:32:37
Oracle
shellnet, 2021-06-23 09:32:37

How to remove Oracle SQL duplicates?

I have a table with multiple columns. Some columns have duplicate values. It is necessary to delete those rows where values ​​are repeated in columns
For example
item column column1 column 2

And similarly, you need to display all duplicate rows

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Akina, 2021-06-23
@warlinx

Output of duplicates:

SELECT t1.*
FROM table t1
WHERE EXISTS ( SELECT NULL
               FROM table t2
               WHERE t1.id <> t2.id -- выражение первичного ключа
                 AND t1.column = t2.column -- для всех полей, кроме первичного ключа

Removal:
DELETE 
FROM table t1
WHERE EXISTS ( SELECT NULL
               FROM table t2
               WHERE t1.id > t2.id -- оставить только запись с минимальным ID
                 AND t1.column = t2.column

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question