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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:39:26+00:00 2026-05-21T16:39:26+00:00

I have 3 tables in my mysql DB to query. Users_rates (fields: id,userid,raterid,rate,eventid) containing

  • 0

I have 3 tables in my mysql DB to query.

enter image description here

  • Users_rates (fields: id,userid,raterid,rate,eventid) containing all of the rates(rate) that have been assigned to users(userid), participating to specific events(eventid), by other users(raterid)

  • Events_participants (fields:id,userid,eventid) containing all of the users(userid) participating to each event(eventid)

  • Users (fields:id,name,lastname)containing all the user relative data

I need to query those three tables to retrieve an event-specific rank for the users’ rates.

Ex. John,Erik and Mark participated to ‘eventid=31’.
John received 1 rate from Mark, and 2 from Erik.
Mark received 1 rate from Erik.
Nobody has rated Erik though.

I need to retrieve for each user name,lastname and the sum of the rates received for eventid=31

I tried with this:

SELECT events_participants.userid,users.name,users.lastname,
(SELECT SUM(rate)FROM users_rates WHERE users_rates.eventid=31 AND users_rates.userid=events_participants.userid)AS rate 
FROM(( events_participants INNER JOIN users ON events_participants.userid=users.id)
LEFT OUTER JOIN users_rates ON events_participants.userid=users_rates.userid )
WHERE events_participants.eventid=31

But I receive:

userid | name | lastname | rate  

1 | luca | silvestro | 1 

3 | claudio | buricchi | 6

3 | claudio | buricchi | 6

What’s the right query?

Thanks

Luca

  • 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-21T16:39:26+00:00Added an answer on May 21, 2026 at 4:39 pm

    Try this:

    SELECT users.userid, users.name, users.lastname, temp.sum as rate
    FROM users LEFT JOIN (
        SELECT userid, SUM(rate) as sum FROM users_rates WHERE eventid = 31 GROUP BY userid
    ) as temp USING (userid)
    

    It might give an error, this might work instead:

    SELECT users.userid, users.name, users.lastname, temp.sum as rate
    FROM users, (
        SELECT userid, SUM(rate) as sum FROM users_rates WHERE eventid = 31 GROUP BY userid
    ) as temp WHERE users.userid = temp.userid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL query that: gets data from three tables linked by unique
I have two mysql tables: USER and ROSTER. Previously, I've been able to query
I need help with a MySQL query. I have three tables: `product_category` ( `id`
I have two different tables, lead and click. I would like to query MySQL
I have a PHP/MySQL query that returns to an HTML table, and I'm stuck
I was thinking that I would have two tables for mysql. One for storing
I have the following tables in MySQL: users profile rates In the users table,
I have been on this mysql query for 2 days running. This is the
i have a MySQL SELECT query which fetches data from 6 tables using Mysql
I have three tables in MySQL that are related, yet not technically linked to

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.