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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:39:00+00:00 2026-06-17T07:39:00+00:00

I have 3 tables users table with user name and user id, leader board

  • 0

I have 3 tables

  • users table with user name and user id,
  • leader board of users with user id and score
  • leader board of likes with user id and numOfLikes

I want to select the name of the user with the most likes, and the name of the users with the most score. But my problem is that when I am writing the query I have duplicated name field there. What should I do?

  • 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-17T07:39:01+00:00Added an answer on June 17, 2026 at 7:39 am

    i use following three tables in my query

    1. usertable – contain username and userid
    2. table2 – contain userid and score
    3. table3 – contain userid and numOfLikes

    To get details of user with max score use following

    select usrtbl.username,usrtbl.userid,tbl2.score from  usertable usrtbl inner join table2 tbl2 on usrtbl.userid=tbl2.userid order by tbl2.score
    desc limit 1
    

    To get details of user with max number of likes use following

    select usrtbl.username,usrtbl.userid,tbl3.numOfLikes from  usertable usrtbl inner join table3 tbl3 on usrtbl.userid=tbl3.userid order by tbl3.numOfLikes
    desc limit 1
    

    To get all in one query use following query

    select usrtbl.username as 'user_with_max_score',usrtbl.userid as 'userid_of_user_with_max_score',
    tbl2.score as 'max_score',usrtbl2.username as 'user_with_max_likes',usrtbl2.userid as 'userid_of_user_with_max_score' ,
    tbl3.numOfLikes as 'max_likes' from  usertable usrtbl2 inner join table3 tbl3 inner join  usertable usrtbl inner join table2 tbl2 
    on usrtbl.userid=tbl2.userid  and usrtbl2.userid=tbl3.userid order by tbl2.score desc,tbl3.numOfLikes desc
     limit 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables user table user_id | name | 1 | peter |
I have Two tables. 1.Users table (Username , Name) 2.Picture table( ID , Username
I have two tables users table: id|name user_relationships id | user_id | friend_id and
I have 2 tables Table: Users userid (int, PK) name (varchar) type (enum) Table:
I have three tables: Users, Groups and GroupsUsers User table: id: 1 username: admin
I have these tables: CREATE TABLE User( Username varchar(15) NOT NULL, Name varchar(20) DEFAULT
I have two tables User id name Result id user_id score created_at Every hour
I have two tables USERS and CALENDER, in calender table user place his availability
I have a user table 'users' that has fields like: id first_name last_name ...
I have two tables: Users: ID, first_name, last_name Networks: user_id, friend_id, status I want

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.