T
T
tolikryg2021-01-25 19:26:41
SQL
tolikryg, 2021-01-25 19:26:41

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

1 answer(s)
L
Lazy @BojackHorseman, 2021-01-25
SQL

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 question

Ask a Question

731 491 924 answers to any question