Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7752963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:55:59+00:00 2026-06-01T11:55:59+00:00

I am running this query which selects a few fields from one table and

  • 0

I am running this query which selects a few fields from one table and returns counts from some other tables.

My problem: if one of my counter fields counts zero, it doesn’t return the number 0, it’s just blank – which is what I would like to try and solve.

SELECT mem.member_id, mem.screen_name, mem.firstname, mem.lastname, mem.country_code, 
mem.joined, rep.rep as reputation, com.cnt as comments FROM members AS mem
LEFT OUTER JOIN (
    SELECT member_id, SUM(awarded_what) as rep
    FROM members_reputation
    GROUP BY member_id) rep
    ON mem.member_id = rep.member_id
LEFT OUTER JOIN (
    SELECT member_id, COUNT(comment_id) as cnt
    FROM blog_comments
    GROUP BY comment_id) com
    ON mem.member_id = com.member_id
GROUP BY mem.member_id
ORDER BY mem.joined DESC

What I would like is something like this:

Screen Name      | Comments
-----------------|--------------------
marty76          | 0
jonnyBoy12       | 0
adamApple        | 12

But, I’m getting something like this instead!

Screen Name      | Comments
-----------------|--------------------
marty76          | 
jonnyBoy12       | 
adamApple        | 12

Using my server side language this is easily fixed, by replacing null values with a zero. But I would like to have the zeros coming straight from SQL so I can order by the counts.

Any suggestions would be marvelous.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:56:00+00:00Added an answer on June 1, 2026 at 11:56 am

    Try the IFNULL Function

    SELECT mem.member_id, mem.screen_name, mem.firstname, mem.lastname, mem.country_code,  
    mem.joined, rep.rep as reputation, IFNULL(com.cnt,0) as comments FROM members AS mem 
    LEFT OUTER JOIN ( 
        SELECT member_id, SUM(awarded_what) as rep 
        FROM members_reputation 
        GROUP BY member_id) rep 
        ON mem.member_id = rep.member_id 
    LEFT OUTER JOIN ( 
        SELECT member_id, COUNT(comment_id) as cnt 
        FROM blog_comments 
        GROUP BY comment_id) com 
        ON mem.member_id = com.member_id 
    GROUP BY mem.member_id 
    ORDER BY mem.joined DESC 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running this query: SELECT TOP 1 [DVD Copy].[Stock No] FROM [DVD Copy] WHERE
I'm new to MySQL, and I'm running this query, SELECT item_id,amount FROM db.invoice_line WHERE
I got this error running a query that goes against 2 tables with combined
I am running this query using CakePHP: $total = $this->Lapse->query(select sum(unix_timestamp(stop) - unix_timestamp(start)) from
I'm running a query that spans 3 tables, none of which have > 55K
I'm running this query SELECT country, countries.code, countries.lat, countries.lng, countries.zoom, worldip.start, worldip.end FROM countries,
Im running this query on the same server as the web application, so SPQuery.ExpandRecurrence
I have problems running a dynamic LIKE statement in my project: this query works
I'm running Mysql 5.0.77 and I'm pretty sure this query should work? SELECT *
My application keeps running into Timeout Expired SqlExceptions. The thing is that this query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.