sql - Same data, different results when using PARTITION BY and ROW_NUMBER -
i have been attempting write script find duplicate records. require 1 of fields same , other 1 different. using below 2 lines in select.
row_number () on (partition col_1 order col_2) 'rownumber', row_number () on (partition col_2 order col_1) 'rownumber2',
once has been used select results temp table both columns > 1. has produced results correct in 1 environment when running same script in environment (backup weekend) results different.
can explain me why happen?
many in advance.
why using row_number? not necessary @ all, should use group by:
select col_1,col_2 yourtable group col_1,col_2 having count(*) > 1
this query return duplicated rows
edit: if have 3rd column deciding dup according it, should do:
select col_3 yourtable group col_3 yourtable having count(*) > 1
Comments
Post a Comment