Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to delete the same record in the oracle library

Shulou Source: shulou.com Published: 2022-06-03 02:09:50 10月02日 Update

How to delete the same record in the oracle library, but keep a record in a duplicate record:

Solution: you can use the rowid pseudo-column in oracle to do this:

1. Create a temporary table and insert the duplicate data from the query (can I create a view?) :

Create table temp_woods as

(select item_id,count (*) as rowcount from wooods group by item_id having count (*) > 1)

two。 Query the same record:

Select A. from woods b where b.item_id in. Rowid from woods a where a.rowid (select max (b.rowid) from woods b where b.item_id in (select item_id from temp_woods) where b.item_id = a.item_id)

3. Delete duplicate records and keep the record with the largest rowid column:

Delete from woods a where a.rowid (select max (b.rowid) from woods b where b.item_id in (select item_id from temp_woods) where b.item_id = a.item_id)

4. Delete temporary tables:

Drop table temp_woods cascade constraints

Tags: Same record query maximum data method purpose View and set Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS NVidia Linux Shulou Technology OPPO Reno