Jump to content

Count()


vchris
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...