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

  • Home
  • SEARCH
  • 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 1099533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:44:58+00:00 2026-05-17T00:44:58+00:00

I have the following MySQL query and tables from which I am querying: SELECT

  • 0

I have the following MySQL query and tables from which I am querying:

SELECT
 `Song`.`id`,
 `Song`.`file_name`,
 `User`.`first_name`,
 `Vote`.`value`,
 Sum(`Vote`.`value`) AS score
FROM `songs` AS `Song`
LEFT JOIN votes AS `Vote` ON (`Song`.`id`=`Vote`.`song_id`)
LEFT JOIN `users` AS `User` ON (`Song`.`user_id` = `User`.`id`)
GROUP BY `Vote`.`song_id`
LIMIT 20;

mysql> describe songs;
+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| id        | int(11)      | NO   | PRI | NULL    | auto_increment | 
| file_name | varchar(255) | NO   |     | NULL    |                | 
| user_id   | int(11)      | NO   |     | NULL    |                | 
| created   | datetime     | NO   |     | NULL    |                | 
| modified  | datetime     | NO   |     | NULL    |                | 
+-----------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql> describe users;
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(11)      | NO   | PRI | NULL    | auto_increment | 
| username   | varchar(255) | NO   |     | NULL    |                | 
| password   | varchar(255) | NO   |     | NULL    |                | 
| first_name | varchar(255) | NO   |     | NULL    |                | 
| last_name  | varchar(255) | NO   |     | NULL    |                | 
| is_admin   | tinyint(1)   | NO   |     | 0       |                | 
| created    | datetime     | NO   |     | NULL    |                | 
| modified   | datetime     | NO   |     | NULL    |                | 
+------------+--------------+------+-----+---------+----------------+

mysql> describe votes;
+----------+----------+------+-----+---------+----------------+
| Field    | Type     | Null | Key | Default | Extra          |
+----------+----------+------+-----+---------+----------------+
| id       | int(11)  | NO   | PRI | NULL    | auto_increment | 
| value    | int(11)  | NO   |     | NULL    |                | 
| song_id  | int(11)  | NO   |     | NULL    |                | 
| user_id  | int(11)  | NO   |     | NULL    |                | 
| created  | datetime | NO   |     | NULL    |                | 
| modified | datetime | NO   |     | NULL    |                | 
+----------+----------+------+-----+---------+----------------+

This query functions just like I want except for one thing. The value returned in the field Vote.value is not from a row that is associated with the user who is logged into the application. I need the score value to be a sum of all the values no matter which user it is associated with, but the Vote.value field should belong to the logged in user (each user only gets one vote record per song).

My first thought is to somehow sort the table so that when the group by happens the vote record for the logged in user is at the top but I have no idea how to do a sort that forces an arbitrary value to the top. Any ideas would be very helpful.

  • 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-17T00:44:58+00:00Added an answer on May 17, 2026 at 12:44 am

    and a third join

    LEFT JOIN votes AS `VotePerUser` ON (`Song`.`id`=`Vote`.`song_id` 
    AND `Song`.`user_id`=`votes`.`user_id`)
    

    and replace the Vote.value with VotePerUser.Value

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

Sidebar

Related Questions

I have the following MySQL query statement: SELECT * FROM table1 INNER JOIN table2
I have the following mysql query: $manufacturers_query = select m.manufacturers_id, m.manufacturers_name, m.manufacturers_image, mi.manufacturers_url from
I have the following query to select users and their locations, etc from MySQL
I have the following MySql query: select t1.* from Table1 t1 inner join Table2
I have the following mysql query, which is producing a list of entries by
I have the following MySQL-query: SELECT s.student_socialnr, s.student_lastname, s.student_firstname, cs.city_name, scp.cpl_startdate, scp.cpl_enddate, scp.cpl_invoice, cu.customer_name,
I have the following mysql query which I am running with php like so.
I have an application that executes the following MySQL query: SELECT 402 AS user_id,
The following MySQL query: select `userID` as uID, (select `siteID` from `users` where `userID`
I have the following query SELECT * FROM (`user_profiles`) WHERE `user_id` = $user_id LIMIT

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.