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 8651715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:08:20+00:00 2026-06-12T14:08:20+00:00

I’ve been working on this issue for awhile and I can’t seem to figure

  • 0

I’ve been working on this issue for awhile and I can’t seem to figure out a way to effectively do this.

Basically I have a table that holds questions and I have a table that keeps track of answers to the questions as well as the user info of the user associated with that answer. The answers are all true or false and I want to keep track of the total true or false answers per each question.

So the first query is selecting all records in the question table.
The second query selects the answers by questionID

I want to create a query that does all of this simultaneously, what I have most recently tried with no success is as follows:

SELECT questions.*, count(answers.*) as total_answers FROM questions
LEFT OUTER JOIN
(
SELECT answers.* AS true FROM votes
WHERE answer = 1 AND questionID = THIS.ID
)

This query doesn’t work because I can’t do another WHERE statement specifying that I want to only grab the records with the answer as 1 or 0 (the true or false answers are all binary). I haven’t found a THIS selector or anything similar in SQL. I hope I have been clear enough. I thought I had a pretty good understanding of Querying until I came across this issue.

Any help would be much appreciated

  • 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-12T14:08:21+00:00Added an answer on June 12, 2026 at 2:08 pm

    Refering to the answer Raphael mentioned, here is another way of writing that:

    Select  Question.*
    ,   Sum(TrueAnswer.answer)
    +   Sum(FalseAnswer.answer)     As  total_answers
    ,   Sum(TrueAnswer.answer)      As  total_TrueAnswer
    ,   Sum(FalseAnswer.answer)     As  total_FalseAnswer
        From    questions       As  Question
        Left    Outer   Join
            answers         As  TrueAnswer
        On  Question.ID     =   TrueAnswer.questionID
        And TrueAnswer.answer   =   1
        Left    Outer   Join
            answers         As  FalseAnswer
        On  Question.ID         =   FalseAnswer.questionID
        And FalseAnswer.answer  =   0
        Group   by  Question.ID 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I have been unable to fix a problem with Java Unicode and encoding. The
Does anyone know how can I replace this 2 symbol below from the string

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.