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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:30:58+00:00 2026-05-24T10:30:58+00:00

I have a MySQL table with the following schema: +———+———+———————-+————+ | User ID |

  • 0

I have a MySQL table with the following schema:

+---------+---------+----------------------+------------+
| User ID | Song ID | Recommending User ID | Created On |
+---------+---------+----------------------+------------+
|  1001   |   54    |        1004          | 2011-07-21 |
|  1002   |   23    |        1005          | 2011-07-28 |
|  1002   |   166   |        1001          | 2011-07-31 |
+---------+---------+----------------------+------------+

What I’m trying to do is give users points when someone favorites a song that they recommend. So the query takes every user in the system and finds out who has the most points in relation to the user its scanning.

So, say we take user 1001. 1001 favorited song id 54 that was recommended by 1004 on 7/21. The query needs to give 40 points when scanning 1001.

Now what makes this complicated is that I want to add a second level. So for each user that 1001 favorited (i.e. 1004) I want to search them (1004) the same way giving anyone 1004 favorited 20 points when still computing 1001.

Just to clarify once more. Let’s take 1002 as an example:

Computing 1002:
    User 1005 gets 40 pts
    User 1001 gets 40 pts
    Computing 1005
         nothing
    Computing 1001
         User 1004 gets 20 pts
Done

Any help on how to start is greatly appreciated 🙂

*Edit: specified mysql

  • 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-24T10:31:00+00:00Added an answer on May 24, 2026 at 10:31 am

    How about this (I’m calling the table you outlined above “Recommendations”):

    Each time a song is marked “favorite,” we need to look whether someone else recommended that. So suppose user UserID just marked SongID as his “favorite.” The following person gets 40 points:

    SELECT Recommending_user_id
    FROM Recommendations 
    WHERE User_id = [UserID] 
    AND Song_id = [SongID]
    

    What you asked is how to check for another level of recommendations. We can do it by a JOIN of the Recommendations table to itself:

    SELECT Forty.Recommending_user_id, Twenty.Recommending_user_id
    FROM Recommendations Forty
    LEFT JOIN Recommendations Twenty
           ON (Forty.Recommending_user_id = Twenty.User_id
           AND Forty.Song_id = Twenty.Song_id)
    WHERE Forty.User_id = [UserID] 
      AND Forty.Song_id = [SongID]
    

    The LEFT JOIN makes sure that if the 20-point user doesn’t exist, it doesn’t break the query; you’ll just get NULL for Twenty.Recommending_user_id.

    Note that you could join again to give 10 points to the third level up, if you wanted. 🙂

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

Sidebar

Related Questions

I have a table with the following schema in MySql 5.1: Venue (id, name,
I have a MySQL table with the following schema: +--------------+-------------+------+-----+---------+----------------+ | Field | Type
I have the following mysql table schema: SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; -- -- Database: `network` --
I have a MySQL table with the following data (simplified): INSERT INTO `stores` (`storeId`,
I have the following MySQL table structure: num field company phone website 1 Gas
I have the following table: mysql> SELECT * FROM `bright_promotion_earnings`; +----+----------+------------+----------+-------+ | id |
I have the following table in MySQL (version 5): id int(10) UNSIGNED No auto_increment
I have the following table structure (in MySQL): DocID, Code, IsDup, DopOf , where
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
I have a table in MySQL That looks like the following: date |storenum |views

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.