Category Paths
Categories form a tree through parent_id. Return category_id and path for every category, where path is the names from the top-level category down to the category, joined by ' > ' (for a top-level category it is just its name, for a child it is 'Parent > Child'). Sort by path.
Hint 1
Start with the rows that have no parent. Then repeatedly add the children of the rows you already have, extending the path.
Reference solution
WITH RECURSIVE tree(category_id, path) AS (
SELECT category_id, name
FROM categories
WHERE parent_id IS NULL
UNION ALL
SELECT c.category_id, t.path || ' > ' || c.name
FROM categories AS c
JOIN tree AS t ON c.parent_id = t.category_id
)
SELECT category_id, path
FROM tree
ORDER BY path;
A recursive CTE has an anchor (here: the top-level categories) and a recursive step (children of rows found so far), glued with UNION ALL. The database repeats the step until it finds no new rows. This is the standard way to walk hierarchies of any depth: org charts, folder trees, bills of materials. Make sure the data has no loops, or the recursion never ends (a depth counter with a limit is a good safety net).