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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:06:14+00:00 2026-06-08T03:06:14+00:00

We have a table (survey) which has different survey questions. Each survey_id only appears

  • 0

We have a table (survey) which has different survey questions. Each survey_id only appears once in this table.

We have a table of votes (vote_survey_table), which logs the user votes for each survey question. The table has fields for survey_id, vote_yes, vote_no, user_id, etc. This table has more than one entry for each survey_id.

I’m trying to query the vote table to add up all the votes for a given survey question, but the query I’m coming up with only adds up the first instance of the row int he vote table.

SELECT survey.survey_id, vote_survey_table.vote_yes AS cnt,
survey.survey_name, survey.survey_details 
FROM survey 
LEFT JOIN vote_survey_table AS votedb ON vote_survey_table.vote_survey_id = survey.survey_id
GROUP BY survey.survey_id
ORDER BY cnt DESC, survey.survey_id LIMIT 0,5

What am I missing on this query that should tell the query to add up all the instances of a survey_id in the vote table and sum up the result? I tried changing the LEFT JOIN to an INNER JOIN, but this didn’t do the trick either.

Thanks in advance as always.

  • 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-08T03:06:16+00:00Added an answer on June 8, 2026 at 3:06 am

    You need to sum the votes.

    SELECT survey.survey_id, SUM(vote_survey_table.vote_yes) AS cnt,
           survey.survey_name, survey.survey_details 
    FROM survey LEFT JOIN vote_survey_table AS votedb 
                  ON vote_survey_table.vote_survey_id = survey.survey_id
    GROUP BY survey.survey_id, survey.survey_name, survey.survey_details 
    ORDER BY cnt DESC, survey.survey_id LIMIT 0,5
    

    If vote_yes is a boolean field, then use COUNT instead of SUM.

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

Sidebar

Related Questions

I have a table which contains asp radiobuttonlists (see below) for a survey. Once
I have a table of surveys which contains (amongst others) the following columns survey_id
I have a StaffLookup table which looks like this. UserSrn | UserName | ManagerSrn
I have a set of data which defines ratings in a survey table for
I have a table which contains a list of Surveys (PK is ID) CREATE
Suppose I have an Oracle 11.2 database containing the following table: TABLE: SURVEY PARAMETER
I have a table of data with survey results, and I want to do
I have table in which I am inserting rows for employee but next time
I have table and this table contain result column with some entries. I just
I have table with 300 000 records (MyISAM). I get record from this table

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.