Table has old insurance policies and their new policy numbers.Like this:
OldPol | NewPol
------ | ------
AA1 | AA2
AA2 | AA3
AA3 | AA5
AA5 | AA9
I need to come up with a query that should show latest policy number for all old policies:
OldPol NewPol
------ -----
AA1 AA9
AA2 AA9
... AA9
AA5 AA9
Tried recursive query - it failed due to allowed max speed or something, self join worked up to 2 levels only. Some policies have only 2 levels, but some has up to 9 levels.