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

  • Home
  • SEARCH
  • 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 8712045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:01:37+00:00 2026-06-13T05:01:37+00:00

How can I get the count is 0 if it is null. when I

  • 0

How can I get the count is 0 if it is null. when I run with the following statement:

SELECT S.shortText, COUNT(O.selectionID) AS C FROM Opinions O
LEFT JOIN Selections S ON S.id=O.selectionID
WHERE S.qID=3 AND MONTH(O.entryDate)=5 
GROUP BY S.shortText

 shortText         C    
 ----------------  ---- 
 Leisure           0       <------ this line missing 
 Business          3
 University visit  1

My Selections Table

 id     shortText        
 -----  ---------------- 
 1      Leisure          
 2      Business         
 3      University visit

My Opinions Table

 id     entryDate              selectionID    
 -----  ---------------------  -------------- 
 186    5/21/2012 11:34:37 AM  2              
 205    5/22/2012 9:13:25 AM   2              
 216    5/22/2012 9:43:14 AM   2              
 237    5/24/2012 8:24:00 PM   3   
  • 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-13T05:01:42+00:00Added an answer on June 13, 2026 at 5:01 am

    If you want to display the Leisure rows as 0 even there is no matching record in opinions table. Use subquery as below:

    select t1.shorttext,if(t2.c is null,0,t2.c)as c from selections t1 left join (
    
    SELECT s.id,S.shortText, COUNT(O.selectionID) AS C FROM selections S
    LEFT JOIN opinions O ON S.id=O.selectionID
    WHERE  MONTH(O.entryDate)=5 
    GROUP BY S.shortText
      ) t2 on t1.id=t2.id
    

    http://sqlfiddle.com/#!2/8ca3e/11

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't run this query in sqlite: Cursor c = mDb.rawQuery( SELECT count(sim1.movie_id) FROM
I have a SQL Statement that works as I want. select COUNT(*), MIN(emailed_to)from email.email_archive
I want to know how we can get record count using reference cursor in
So i need to figure out how i can get a record count value
In Rails 3.1, how can I get a count of the number of attributes
Can I get a threads suspend count under Windows CE, using C or Visual
How can i get result My Dream Table Result CREATE TABLE #temp( [count] int
Can anyone help me with the question. I'm trying to get msmq messages count
How can you get unbuffered output from cout, so that it instantly writes to
Can get all triples with value null in specific field? All people with date_of_birth

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.