Skip to content

Instantly share code, notes, and snippets.

@MatthewRDodds
Created September 2, 2015 15:15
Show Gist options
  • Save MatthewRDodds/ae6500e38440cebf65f0 to your computer and use it in GitHub Desktop.
Save MatthewRDodds/ae6500e38440cebf65f0 to your computer and use it in GitHub Desktop.
SELECT *
FROM posts
INNER JOIN category_joins as filter_categories_join
ON filter_categories_join.categorizable_id = posts.id
AND filter_categories_join.categorizable_type = 'Post'
INNER JOIN categories as filter_categories
ON filter_categories.id = filter_categories_join.category_id
INNER JOIN category_joins as categories_join_1
ON categories_join_1.categorizable_id = posts.id
AND categories_join_1.categorizable_type = 'Post'
INNER JOIN categories as categories_1
ON categories_1.id = categories_join_1.category_id
INNER JOIN category_joins as categories_join_2
ON categories_join_2.categorizable_id = posts.id
AND categories_join_2.categorizable_type = 'Post'
INNER JOIN categories as categories_2
ON categories_2.id = categories_join_2.category_id
WHERE filter_categories.lft BETWEEN 14 AND 115
AND categories_1.lft BETWEEN 133 AND 134
AND categories_2.lft BETWEEN 137 AND 138
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment