I have a table content_folder_tbl that has a list of all folders and sub folders defined with folder_id and parent_id
I want to get all the folders id once I define the root folder_id.
As a workaround I came up with this query :
select *
from content_folder_tbl
where folder_id in (select folder_id
from content_folder_tbl
where parent_id = 73
UNION
Select folder_id
from content_folder_tbl
where parent_id in (select folder_id
from content_folder_tbl
where parent_id = 73)
Union
Select folder_id
from content_folder_tbl
where parent_id in (Select folder_id
from content_folder_tbl
where parent_id in (select folder_id
from content_folder_tbl
where parent_id = 73))
)
It returns exactly what I want, but it's redundant and works only if I have 3 levels folders.
How to rewrite this query to return values for any level (looks like I need a recursive approach)?
73 is the root folder_id in this case
Example of expected result:
