Hey all,
Got this table in SQL Server 2005, which is used to maintain a history of merging operations:
- Column FROM_ID (int)
- Column TO_ID (int)
Now I need a query that takes the original FROM_ID as input, and returns the last available TO_ID.
So for instance:
- ID 1 is merged to ID 2
- Later on, ID 2 is merged to ID 3
- Again later, ID 3 is merged to ID 4
So the query I'm trying to put together will take as input (in the WHERE clause I presume) ID 1, and should give me the last available TO_ID as a result, in this case 4.
I suppose I need some recursion logic, but don't really know how to start.
Thanks !
Mathieu