You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now, if I want to find the root parent of any given service I can do a query like:
WITH RECURSIVE cte AS (
SELECT id, parentid
FROM services
WHERE id = 'given_id'
UNION ALL
SELECT s.id, s.parentid
FROM services s
JOIN cte ON s.id = cte.parentid
)
SELECT id, parentid
FROM cte
WHERE parentid IS NULL;
I tried to wrap the WITH RECURSIVE cte AS (... part in a select($qb->raw('WITH RECURSIVE cte AS (...')) but it didn't work. Is there any way to really place the CTE before the rest of the generated query?
Thank you.
The text was updated successfully, but these errors were encountered:
Is it possible to write queries that include a recursive common table expression (CTE) for recursive operations?
Considering the following
services
table that has a tree structure of multiple items that can be children of others:Now, if I want to find the root parent of any given
service
I can do a query like:I tried to wrap the
WITH RECURSIVE cte AS (...
part in aselect($qb->raw('WITH RECURSIVE cte AS (...'))
but it didn't work. Is there any way to really place the CTE before the rest of the generated query?Thank you.
The text was updated successfully, but these errors were encountered: