Skip to content
Advertisement

Oracle Remove Duplicates and Update Rows in a Table with a Value from Another Table

In my associates table I have 4,978 people with at least 1 duplicate.

Each duplicate for a person has a unique id (asscid) in the associates table.

My cases table has a case tied to each asscid

I would like to take each person that has a duplicate, grab the latest asscid that person has from the associates table and update the cases table. Results would be:

Advertisement

Answer

If I understand correctly, you want:

This assumes that the “latest” asscid is the one with the largest value. If you have another column that specifies the ordering (such as a date), then you can use first_value() instead.

EDIT:

If you actually want to update the data:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement