I have a cat table that has the following columns:
cat_id  | name            |   parent_id
1         cat1                1
2         subcat1             1
3         subcat1-subcat      2
This table has thousands of categories but that is the general structure.
When a user selects a top level category I have a query to get its children like this:
SELECT * FROM cat WHERE parent = $id
My problem is that I need to know if these children categories have children of their own.
I could do a loop on the results and do a query for each category returned, but I am hoping that there is a solution where I can use just one query, maybe it will require a sub query?
Thanks for the help.