I've got objects with an hierarchical order. Each object has an ID, a parent object (TO_ID in the table) and a type.
My data is in a table which looks like this:
ID | TO_ID | TYPE
123 | 103 | group
176 | 103 | field
256 | 169 | group
103 | 234 | organization
234 | 390 | site
Now I want to search through the table until I find a parent object with a specific type (I don't know how many parent objects my start object has).
For example I start with ID 123 and want to find the ID of the parent object with TYPE site.
How can I solve this with SQL?