I have a tree of categories in my database. I also have a table of items associated with the tree by a category id.
Now, I want to list all items in a specific category and its children and their children, etc...
For now, I proceed this way:
- Retrieve the id of all concerned categories.
- Make a query in the items table with a WHERE clause like this: WHERE cat_id=2 OR cat_id=10 OR ...
I think this way cause the query to be very slow and very long if I have a lot of categories. A search can be in 100 categories sometimes.
Is there a better practice?