Skip to content

Instantly share code, notes, and snippets.

@duyet
Created December 8, 2015 07:10
Show Gist options
  • Save duyet/8f340b64225b84cb639c to your computer and use it in GitHub Desktop.
Save duyet/8f340b64225b84cb639c to your computer and use it in GitHub Desktop.
SELECT
t1.id as level_1,
t4.level_2,
t4.level_3
FROM
`categories` t1
LEFT JOIN (
SELECT
t2.id as level_2,
t2.parent_id as level_2_parent_id,
t3.id as level_3
FROM
`categories` t2
LEFT JOIN `categories` t3 ON t2.id = t3.parent_id
) as t4 ON t1.id = t4.level_2_parent_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment