Hello – I am trying to construct an Oracle 11g query that will find the latest version of an entity by going through a table that has a history of moves. An example of this is that the table could contain a list of addresses that a person has lived at and different addresses that they have moved to.
For example, you might live at ADDRESS_ID 123 but then moved to ADDRESS_ID 456 and moved again to ADDRESS_ID 789.
It is also possible that you lived at ADDRESS_ID 123 the whole time and never moved therefore you would never appear on the MOVE_LIST table.
The goal of the query would be so if I select ADDRESS_ID 123 in the first example above then it would tell me the MOST RECENT ADDRESS_ID that the person is at (789).
The table is called MOVE_LIST and has the following columns: MOVE_LIST_ID ORIGINAL_ADDRESS_ID DESTINATION_ADDRESS_ID
The query I have so far doesn’t complete this task since it doesn’t go through the list of moves:
Select DESTINATION_ADDRESS_ID
from MOVE_LIST
where ORIGINAL_ADDRESS_ID = '123'
Any tips on this query would be GREATLY appreciated.
Here is some sample data:
MOVED_LIST_ID ORIGINAL_ADDRESS_ID DESTINATION_ADDRESS_ID
1 123 456
2 456 789
Thank you