Can those who have the know-how help me with this problem?
So it's a table with Id and Previous_Id (don't know why, it's just the way the developers have made it..)
Now, I need a Select that starts from Id, checks for possible Previous_Id and jumps to that Id which has no Previous_Id (Null).
I mean, if Id has Previous_Id (i.e. it's not Null), then the Previous_Id is read as the main Id and then again you look to find out if there's any Previous_Id facing it - if yes, you do the same until you get to Null. It's that last Id which I need along with the first Id where it all started.
But how can this be done with Select?
I'd create a PL/SQL function which grabs the most recent ID, where you pass in the root ID. So your main SQL would grab anything where PREVIOUS_ID is null, and pass the main ID into this procedure. Basically, go in the reverse order from what you described.
Let PL/SQL walk up the chain... or... you might be able to slim down the code within that function, using CONNECT BY and LEVEL in your embedded SQL ...