Retrieve cateogory header only once (joining 2 tables)
Hi there guys,
I have two tables; one table contains the product category headers and the other table containing the products.
This table contains the headers; Sublevel
CategoryID SublevelID Name
---------------------------------
67 1 Anaesthsia Thermometers
67 2 Forehead Thermometers
67 3 Drug Testing Thermometers
67 4 Drug Testing Thermometers
The table containing the products; Subcat1
CategoryID SublevelID Name
---------------------------------
67 2 12 Level Thermometer
67 1 Clinitrend
67 2 Forehead Thermometer
67 3 Briteline
67 3 BriteEvent
I would like to query those two tables so the end result would be like this
Here is eventually what the end result to be;
Anaesthesia Thermometers - Clinitrend (and the rest of products with SublevelID that matches)
Forehead Thermometers - 6 Event Reversible (and the rest of products with SublevelID that matches)
My current sql query looks like this;
PHP Code:
$query = "SELECT sublevel.Name, sublevel.SubLevelID, sublevel.CategoryID, subcat1.CategoryID, subcat1.SubCatID, subcat1.SubLevelID, subcat1.SubCatName, subcat1.SubCatImage FROM sublevel, subcat1 WHERE sublevel.CategoryID = $cat_id AND subcat1.CategoryID = $cat_id AND subcat1.SubLevelID = sublevel.SubLevelID ORDER BY subcat1.SubLevelID ";
Although this does the job because it retrieves the category header and it's products, it repeats the header which i can understand why but i don't know how to retrieve it once.
Can anyone point me in the right direction?