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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:52:25+00:00 2026-05-23T14:52:25+00:00

I have a ballot where each voter gets 3 votes, choosing from 10 different

  • 0

I have a ballot where each voter gets 3 votes, choosing from 10 different candidates. Vote 1 is allocated 3 points, vote 2 gets 2 points and vote 3 gets 1 point.

I have the following SQL queries to total the number of points gained from each of the votes (so separate results for votes 1, 2 and 3).

What I need to do is put all these results together in a single table, but I’m not too sure where to start.

SELECT cn.cand_name, (count(vote_1) * 3) as vote_1 FROM candidate_votes cv Inner Join candidate_names cn ON cv.vote_1 = cn.cand_number GROUP BY cand_name;

SELECT cn.cand_name, (count(vote_2) * 2) as vote_2 FROM candidate_votes cv Inner Join candidate_names cn ON cv.vote_2 = cn.cand_number GROUP BY cand_name;

SELECT cn.cand_name, (count(vote_3) * 1) as vote_3 FROM candidate_votes cv Inner Join candidate_names cn ON cv.vote_3 = cn.cand_number GROUP BY cand_name;

I have the following results table:

Voter_number    Vote_1     Vote2      Vote3
123             cand_1     cand_3     cand_2
456             cand_2     cand_1     cand_3
789             cand_2     cand_3     cand_1

And the following candidate name table:

cand_number     cand_name
cand_1          Dave
cand_2          Sarah
cand_3          Nigel

So the results I’m looking for will look something like:

Candidate       Votes
Dave            6
Sarah           7
Nigel           5
  • 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-05-23T14:52:26+00:00Added an answer on May 23, 2026 at 2:52 pm
    SELECT cn.cand_name
         , COALESCE(cv1.cnt_1,0)
         , COALESCE(cv2.cnt_2,0)
         , COALESCE(cv3.cnt_3,0)
         , 3*COALESCE(cv1.cnt_1,0) + 2*COALESCE(cv2.cnt_2,0)
           + 1*COALESCE(cv3.cnt_3,0) AS total
    FROM candidate_names AS cn
      LEFT JOIN 
        ( SELECT vote_1 AS vote
               , COUNT(*) AS cnt_1
          FROM candidate_votes cv
          GROUP BY vote_1
        ) AS cv1
        ON cv1.vote = cn.cand_number
      LEFT JOIN 
        ( SELECT vote_2 AS vote
               , COUNT(*) AS cnt_2
          FROM candidate_votes cv
          GROUP BY vote_2
        ) AS cv2
        ON cv2.vote = cn.cand_number
      LEFT JOIN 
        ( SELECT vote_3 AS vote
               , COUNT(*) AS cnt_2
          FROM candidate_votes cv
          GROUP BY vote_3
        ) AS cv3
        ON cv3.vote = cn.cand_number
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query: SELECT COUNT(*) as votes, a.member_id FROM ballots a WHERE ballot_id
have a nice day. I got problem when trying to create an image from
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
Have converted devise new session from erb to Haml but doens't work, this is
Have a look at the following code to find X^y. /* Find exponent in
I have the following code that gives me a bunch of locations and an
Have one Doubt In MVC Architecture we can able to pass data from Controller
I have the following code which sets up some custom form elements on the
Have whats probably a simple problem with using parent in if and each statements
Have a recurring situation, petty I know, but I'd like to consolidate the following:

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.