I am kind of new to the more advanced topics of PLSQL, so hopefully someone can help me out.
The problem: I have a table with messages sent between
In Oracle this is easily done using CONNECT BY
select message_id, parent_id, message_content
from messages
start with message_id = 97 -- this is the root of your conversation
connect by prior message_id = parent_id;
This walks the tree from top to bottom.
If you want to walk the tree from a single message to the root, change the start with and the connect by part:
select message_id, parent_id, message_content
from messages
start with message_id = 100 -- this is the root of your conversation
connect by prior parent_id = message_id; -- this now goes "up" in the tree