Answer the question
In order to leave comments, you need to log in
How to combine requests to get products from a category and its subcategory?
Hello everyone, there is such a request that takes products from all sub-subcategories, this is necessary for a subcategory. I realized that it does not take products from the subcategory itself, but only from all subsubcategories, I need to show products from both the subcategory and its subsubcategories.
Simply put, all products of the selected subcategory and subsubcategories! I will be very grateful!
SELECT DISTINCT g.* FROM products g JOIN subsubcategories c ON c.id = g.category_id WHERE c.parent_id = :category_id AND g.type_category = 'subsub'
Answer the question
In order to leave comments, you need to log in
join explicitly n times, where n is the height of the tree
recursive cte
change tree storage schema
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question