Jump to content

Count()


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...