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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:42:27+00:00 2026-06-13T01:42:27+00:00

I am building a polling system and I have a query right now that

  • 0

I am building a polling system and I have a query right now that is supposed to select all of the polls and count all of the votes for each of the polls (which lie in a separate table). So my tables look like:

Polls:  
ID  
Title  
Body

Votes:  
ID  
PollID  
Vote  (This value is either 0 or 1)

Well the totaling of the votes looks like it is working, the issue is that it is currently only displaying one record.

Currently my query looks like this:

SELECT POLLS.ID, 
       POLLS.TITLE, 
       POLLS.BODY, 
       Sum(CASE 
             WHEN VOTES.VOTE = 1 
                  AND VOTES.POLLID = POLLS.ID THEN 1 
             ELSE 0 
           END) AS yay, 
       Sum(CASE 
             WHEN VOTES.VOTE = 0 
                  AND VOTES.POLLID = POLLS.ID THEN 1 
             ELSE 0 
           END) AS nay, 
       FROM     polls, 
       VOTES 
ORDER  BY POLLS.ID 

Also I am using PHP with Codeigniter.

  • 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-13T01:42:28+00:00Added an answer on June 13, 2026 at 1:42 am
    SELECT polls.ID,polls.title,polls.body,
      SUM(case when votes.vote = 1 then 1 else 0 end) AS yay,
      SUM(case when votes.vote = 0 then 1 else 0 end) AS nay,
    FROM polls 
    JOIN votes ON polls.ID = votes.pollID
      GROUP BY poll.ID, polls.title, polls.body
      ORDER BY polls.ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Building an inventory system. I have lots of products and each product has three
Im building a application that needs to poll a webserver alot. Right now i
I have been building a real-time notification system. It’s part of a web application,
In the application I'm building I'm polling for a status update and I have
I'm building a component of a web page that needs relatively constant database polling.
I have an application I'm building that's using the NetCDF C++ library, and NetCDF
I am currently building a dynamic url tab system that user can say what
Im building an app that uses long polling technique and im running into some
Background: I'm building a small application that will be run daily, pulling data from
building a site using PHP and MySQL that needs to store a lot of

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.