Jump to content

Get count even if zero is returned


The Little Guy

Recommended Posts

I would like to get a count, even if there is a count of zero.

 

example: I have 2 domains in the database, each domain has zero searches on them, I would still like to get them, but display 0 for the count. Any suggestions on what I should do? I can't seem to think how.

 

select d.domain, count(*) total from domains d left join searches s on(d.domain_id = s.domain_id and d.member_id = 1) group by d.domain_id

 

Thanks for the help!

Link to comment
Share on other sites

I would like to get a count, even if there is a count of zero.

 

example: I have 2 domains in the database, each domain has zero searches on them, I would still like to get them, but display 0 for the count. Any suggestions on what I should do? I can't seem to think how.

 

select d.domain, count(*) total from domains d left join searches s on(d.domain_id = s.domain_id and d.member_id = 1) group by d.domain_id

 

Thanks for the help!

Are you saying that you don't get back 2 records?

Link to comment
Share on other sites

I would like to get a count, even if there is a count of zero.

 

example: I have 2 domains in the database, each domain has zero searches on them, I would still like to get them, but display 0 for the count. Any suggestions on what I should do? I can't seem to think how.

 

select d.domain, count(*) total from domains d left join searches s on(d.domain_id = s.domain_id and d.member_id = 1) group by d.domain_id

 

Thanks for the help!

Are you saying that you don't get back 2 records?

 

Correct. I should get back 2 records, and count should contain 0 for both.

 

@joel24 that doesn't work, as it comes back with a count of 1.

 

I should note that the searches table has 0 records in it.

Link to comment
Share on other sites

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.