I have 2 tables: shop_products and shop_category.
shop_products: id, name, category_id
shop_category: id, name, parent_id, active. Active can be 'true' or 'false'.
Categories are nested like parent>subcat>subsubcat>...
How is it possible to get all products where top parent category active is 'true'?
I tried to use JOIN. But it takes only closest category, not the top category of tree.
SELECT * FROM shop_products
INNER JOIN shop_category as sc1 ON (shop_products.category_id=sc1.id)
INNER JOIN shop_category as sc2 ON (sc1.parent_id=sc2.id)
WHERE sc2.active=1
UPD: Here is sqlfiddle
I expect to get nothing. Because the top category 'Cat1' has active false