Jump to content

[SOLVED] How do I count 0's in a group by query


Recommended Posts

Hi

 

I am fairly new to php and mySQL I have the following query

 

SELECT
`type`.id,
`type`.category,
`type`.description,
Count(item.category_id)
FROM
`type`
Inner Join item ON `type`.id = item.category_id
GROUP BY
`type`.id
ORDER BY
`type`.category ASC

 

This returns the results I expect where there are items in the type table that correspond to a category_id BUT I want this query to also return 0 values of category.

 

The result that I want would be something like:

 

Bridge 1

Compact  0

DSLR 3

 

but all I am getting is

 

Bridge 1

DSLR 3

 

Any pointers most welcome. I have spent a couple of hours searching Google without success.

 

TIA

 

--

Colin

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.