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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:02:49+00:00 2026-06-06T19:02:49+00:00

I have two tables, username and score . Both are connected using user_id .

  • 0

I have two tables, username and score. Both are connected using user_id.

I want to select the top 5 usernames who have the highest score. I am trying following query but it is not working:

SELECT `user_name`  
  FROM `username` 
 WHERE `user_id` = ( SELECT `u_id` 
                       FROM `score` 
                       ORDER BY `high_score` DESC 
                       LIMIT 5 )

I get this error when I run the above query: #1242 - Subquery returns more than 1 row

  • 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-06-06T19:02:52+00:00Added an answer on June 6, 2026 at 7:02 pm

    In your WHERE clause your are trying to assert the congruence or equality of one value (on the left side) to a list of values (on the right side).

    Use the IN operator to achieve this because it will compare the left value with any of the right values.

    The following is your corrected code.

    SELECT    `user_name`
        FROM  `username`
        WHERE `user_id` IN(
                  SELECT        `u_id`
                      FROM      `score`
                      ORDER BY  `high_score` DESC
                      LIMIT 5
                  );
    

    As a manner of style using a join is clearer and more elegant especially for a simple query like this.

    SELECT        `u`.`user_name`
        FROM      `username` AS `u`
        INNER JOIN `score` AS `s`
            ON     `u`.`user_id` = `s`.`u_id`
        ORDER BY  `s`.`high_score` DESC
        LIMIT      5;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables in my database who looks like this: User: userid(int) username(varchar)
I have two tables users(id, username, password) and user_badges(user_id, badge_id, badge_slot) I would like
hope someone can help. I have two tables: Users -UserID -UserName UsersType -UserTypeID -UserID
I have Two tables. 1.Users table (Username , Name) 2.Picture table( ID , Username
I have the following two tables: auth_user id username is_active (boolean) ... useprofile_userprofile id
I have two tables on a webform. On a button click I want to
i have two tables both are related with primary-foreign key ralation and i have
We have two tables: Vehicle: Id RegistrationNumber LastAllocationUserName LastAllocationDate LastAllocationId Allocations: Id VehicleId UserName
I have two tables reports and holidays . reports : (username varchar(30),activity varchar(30),hours int(3),report_date
I have two tables reports and holidays . reports : (username varchar(30),activity varchar(30),hours int(3),report_date

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.