I have a table like this.
ID Name Source ID 1 Orange 0 2 Pear 0 3 Apple 0 4 Orange 0 5 Apple 0 6 Banana 0 7 Orange 0
What I want to do is:
- For the records with FIRST occurrence of "Name", I want to update the "Source Id" with the "Id" value
- For the records with SECOND and CONSECUTIVE occurrences of "Name", I want to update the "Source Id" with the "Id" value of the FIRST occurrence
So, the table should be updated as follows:
ID Name Source ID 1 Orange 1 2 Pear 2 3 Apple 3 4 Orange 1 5 Apple 3 6 Banana 6 7 Orange 1
How can I do it in SQL (Oracle to be in particular, but I'm fine with General SQL as well) ...
Thanks!