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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:54:59+00:00 2026-05-27T11:54:59+00:00

I have 9 items in a problem_categories tables that have category_id = 1 When

  • 0

I have 9 items in a problem_categories tables that have category_id = 1

When I do this query:

select problems.problem_id , problem_title , sum( vote ) as totalVotes 
from problems 
left join problem_votes on problems.problem_id = problem_votes.problem_id 
left join problem_categories on problems.problem_id = problem_categories.problem_id  
where problem_categories.category_id = 1; 

I get 1 row with a complete sum of all the votes for the 9 items. But what I was really looking for was the 9 rows with a vote sum for each. Any idea what is wrong with my query just by looking at it?

My tables are

problem - lists problem information
problem_votes - has a record per vote for each problem
problem_categories - table keeping a problem_id and a category_id so that a problem can be in a certain category

Thanks,
Alex

  • 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-27T11:54:59+00:00Added an answer on May 27, 2026 at 11:54 am

    You need to tell MySQL what you’re grouping by. Right now it thinks you want EVERYTHING grouped into one row. If you want it to by grouped by problem_title, then add in this line after your WHERE:

    GROUP BY problem_title
    

    This will cause you to get a different row for each unique problem_title, and the sum will only count records matching that title.

    Edit:

    So the whole query will look something like this:

    select problems.problem_id , problem_title , sum( vote ) as totalVotes 
    from problems 
    left join problem_votes on problems.problem_id = problem_votes.problem_id 
    left join problem_categories on problems.problem_id = problem_categories.problem_id  
    where problem_categories.category_id = 1
    group by problem_title; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query SELECT products_list.id_cat_unique, products_categories_list.*, COUNT(products_list.id_cat_unique) as counter FROM products_categories_ids LEFT JOIN
I have items in a list in a SharePoint 2003 site that I need
I'm doing custom drawing in datagridview cells and I have items that can vertically
WPF controls have certain properties (UserControl.Resources, UserControl.CommandBindings) that can have items added to them
I have a big mysql query which needs to trawl through 4 tables to
I have an xml output like this: <data> <item-types> <entry id=1 items=5> <category>Frozen</category> </entry>
I have a bunch of items in my program that all belong to a
I have a form here that I can get to autocomplete with hard-coded items
I have a problem with sorting items in table in PHP. Here is what
I have a annoying problem .. I want my first 4 items in a

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.