I have a table which has these columns: id, text, parentid. And when a row is a root item (doesn't have any parent item), then parentid = 0.
What I want to do, is find text of the first root (root of root of ... root of item) of a specific item.
Here's an example:
SELECT parentid FROM cat WHERE id = 1234 --returns 1120
SELECT parentid FROM cat WHERE id = 1120 --returns 1011
SELECT parentid FROM cat WHERE id = 1011 --returns 0. So this the first root.
SELECT text FROM cat WHERE id = 1011 --returns what I want.
I know it's easily possible with Loops, but I'm using sqlite which doesn't support loops.
So, the question is, is there any way to implement this in sqlite without using any other scripts?