Skip to content

Instantly share code, notes, and snippets.

@ssatz
Created June 26, 2018 07:14
Show Gist options
  • Save ssatz/8f8c4a168bd2ef928c430e2c6a66e0d0 to your computer and use it in GitHub Desktop.
Save ssatz/8f8c4a168bd2ef928c430e2c6a66e0d0 to your computer and use it in GitHub Desktop.
SELECT t1.name AS lev1, t2.name as lev2, t3.name as lev3, t4.name as lev4
FROM `categories` AS t1
LEFT JOIN categories AS t2 ON t2.parent_id = t1.id
LEFT JOIN categories AS t3 ON t3.parent_id = t2.id
LEFT JOIN categories AS t4 ON t4.parent_id = t3.id
WHERE t1.id = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment