selecting categories and sub categories
Posted: Sat Jan 13, 2007 2:34 pm
I have a two tables, one categories and one sub_categories, the sub_categories are assocated to a category, so a category may have 10 sub_categories, etc.
I want to display this as such
Category 1
Sub Category 1
Sub Category 2
Category 2
Sub Category 1
Sub Category 2
Sub Category 3
This is the query i have so far...
The problem is that the category name repeats for however many sub categories there are.
Does anyone know how I would do it so the category name only repeats once, regardless of the number of sub categories?
I want to display this as such
Category 1
Sub Category 1
Sub Category 2
Category 2
Sub Category 1
Sub Category 2
Sub Category 3
This is the query i have so far...
Code: Select all
SELECT a.name AS cat_name, a.category_id AS cat_id, b.sub_category_id AS sub_id, b.name AS sub_name
FROM `categories` a
LEFT JOIN sub_categories b ON a.category_id = b.category_id
GROUP BY cat_id, sub_id
ORDER BY cat_name ASC
LIMIT 0 , 30Does anyone know how I would do it so the category name only repeats once, regardless of the number of sub categories?