Handling Duplicate Records
Handling Duplicate Records
records**----------------------------------------------------------
Finding duplicates:
-->if count(*) >1 then the records has duplicates
1)using rowid:
>>delete from table_name
where rowid not in
(select max(rowid) from table_name
group by col1,col2,col3...)
2) using distinct:
>>select distinct * from table_name?
or
>> create new_table as select distinct * from old_table
note: distinct method is not preferble because it is costly excution (it will
filter all the records)
-----------------------------------------------------------------------------------
----------------------------------------------------------
what is rowid and what is use of rowid?
note --> rowid is availble in only Oracle
rowid:
- It is a pseudo column that provides a way to directly access a row.
- represents the unique address or identifier for a specific row in a table.
note - rowid is unique address to each rows (for duplicates also there will be
different rowid address)
AAAR5MAAEAAAJpbAAC
AAAR5MAAEAAAJpbAAD
AAAR5MAAEAAAJpbAAB
AAAR5MAAEAAAJpbAAF
AAAR5MAAEAAAJpbAAE
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------
how do you handle duplicate records?
primary key --> Use primary keys or unique constraints to prevent the insertion of
duplicate records.
querying -->Use DISTINCT in SELECT statements to retrieve only unique records when
querying data.
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------