So I have an SQL query to retrieve all the children of a given node in an adjacency list.
WITH RECURSIVE
q AS
(
SELECT id, name
FROM categories h
WHERE id = 11846801
UNION ALL
SELECT hc.id, hc.name
FROM q
JOIN categories hc
ON hc.parent = q.id
)
SELECT name
FROM q
Is there a way to modify this query to return me just the bottom level of nodes? I can't just specify a given level as each path may have a different depth.