Home > Database > SQL > Oracle deletes duplicate data and keeps the first record

Oracle deletes duplicate data and keeps the first record

angryTom
Release: 2020-02-29 10:37:46
Original
8618 people have browsed it

Oracle deletes duplicate data and keeps the first record

oracle deletes duplicate data and retains the first record

1. Find the redundant duplicate records in the table. Duplicate records are based on a single field ( Id) to judge

select * from 表 where Id in (select Id from 表 group byId having count(Id) > 1)
Copy after login

2. Delete redundant duplicate records in the table. Duplicate records are judged based on a single field (Id), leaving only the record with the smallest rowid

DELETE from 表 WHERE (id) IN ( SELECT id FROM 表 GROUP BY id HAVING COUNT(id) > 1) AND ROWID NOT IN (SELECT MIN(ROWID) FROM 表 GROUP BY id HAVING COUNT(*) > 1);
Copy after login

3. Search Redundant duplicate records (multiple fields) in the table

select * from 表 a where (a.Id,a.seq) in(select Id,seq from 表 group by Id,seq having count(*) > 1)
Copy after login

4. Delete redundant duplicate records (multiple fields) in the table, leaving only the record with the smallest rowid

delete from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select min(rowid) from 表 group by Id,seq having count(*)>1)
Copy after login

5. Search The redundant duplicate records (multiple fields) in the table do not include the record with the smallest rowid

select * from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select min(rowid) from 表 group by Id,seq having count(*)>1)
Copy after login

PHP Chinese website, there are a large number of free SQL tutorials, everyone is welcome to learn!

The above is the detailed content of Oracle deletes duplicate data and keeps the first record. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template