Thursday 21 February 2013

How to identify a duplicate records in a table ?

Let us assume, i have a product_table with columns product_id, product_desc

Table name : product_table


Product_id Product_desc
10 XYZ
10 XYZ
20 ABC
20 ABC
30 TTT

by using group by and having we can find the duplicate records


Query : select product_id from product_table group by product_id having count(*)>1

Another way to find the duplicate records

Query : sel * qualify row_number() over(partition by product_id order by product_desc)>1 from product_table

or

Query: select product_id,product_desc,row_number() over(partition by product_id order by product_desc) r from product_table qualify r>1


Please drop comments here any other way is there to find the duplicate records.

No comments:

Post a Comment