using this query:
SELECT ARCustomerCode,
count(ARCustomerCode)
FROM customers
group by ARCustomerCode
having count(ARCustomerCode) > 1;
I am able to identify the number of rows where ARCustomerCode is not unique. How can I update each duplicate ARCustomerCode field by appending the unique row id?
Appreciate the insight!
2
Answers
You can exploit the
ROW_NUMBER
window function to assign a ranking to each duplicate of "ARCustomerCode" values, then update only the records which have ranking > 1 (all duplicates) for each code.It’s even simpler if you don’t need to append a number to the first instance of the dup.