vchris 3 Posted March 16, 2009 Report Share Posted March 16, 2009 I'm trying to count the number of items in a given category or subcategory. MySQL SELECT `cxs_cat_id`, `cxs_subcat_id`, `cat_name_e`, `subcat_name_e`, COUNT(item_id) AS `total_items`FROM `items`, `cat_x_subcat`, `categories`, `subcategories`WHERE `cxs_cat_id` = `cat_id` AND `cxs_subcat_id` = `subcat_id` AND `item_cxs_id` = `cxs_id`GROUP BY `cxs_cat_id`, `cxs_subcat_id`, `cat_name_e`, `subcat_name_e`ORDER BY `cat_name_e` Output * General (1) o Electronics (1) * Vehicles (1) o Cars (1) o Trucks (1)I seem to only be getting 1 (in parenthesis) as the count. I have 3 items, 2 categories and 3 subcategories. Quote Link to post Share on other sites
Stefano 0 Posted March 23, 2009 Report Share Posted March 23, 2009 It looks like there is some row that don't match among tables. Try with outer joins. By the way, I can't get the sense of the "order by clause" at the end of "group by query"...regardsStefano De Boni Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.