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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:27:58+00:00 2026-06-05T15:27:58+00:00

So I have this game database, where I have several users with fields, id,

  • 0

So I have this game database, where I have several users with fields, id, name, points

I need a rank table for a specific user where its position can be seen in relation to the amount of points, there is room for 8 positions in the table, so I was looking for a way to do the following:

if I do SELECT * FROM users WHERE id = {user_id} ORDER By points Select the 4 results before and the 3 results after this id. is there a query to do this? the result should look like:

---------------------
|id   |name  |points|
---------------------
| 52  |name1 | 10   |
---------------------
| 23  |name1 | 09   |
---------------------
| 93  |name1 | 08   |
---------------------
| 12  |name1 | 07   |
---------------------
| 43  |queried_name1 | 06   |
---------------------
| 67  |name1 | 05   |
---------------------
| 32  |name1 | 04   |
---------------------
| 91  |name1 | 03   |
---------------------

I was trying to make this by software but it is pretty slow to iterate trough all the results. Thanks for your help!

  • 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-05T15:27:59+00:00Added an answer on June 5, 2026 at 3:27 pm

    Like that, I would say, for the above results:

    SELECT * FROM users WHERE points > (SELECT points FROM users WHERE id = {user_id}) ORDER By points ASC LIMIT 3;
    

    For the below results:

    SELECT * FROM users WHERE points < (SELECT points FROM users WHERE id = {user_id}) ORDER By points DESC LIMIT 4;
    

    So, with a big union, it would give:

    SELECT * FROM (SELECT * FROM users WHERE points > (SELECT points FROM users WHERE id = {user_id}) ORDER By points ASC LIMIT 3 ) a 
    UNION
    SELECT * FROM users WHERE id = {user_id}
    UNION
    SELECT * FROM (    SELECT * FROM users WHERE points < (SELECT points FROM users WHERE id = {user_id}) ORDER By points DESC LIMIT 4 ) b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my database I have 5 tables: game(game_id,name,...) tag (tag_id,name,...) collection (coll_id,name,...) collections_tags (id,coll_id,tag_id)
I have this data in database: table: games_related game_id1 | game_id2 3 | 2
I have a database results table with the following fields: game_id, home_team, away_team, home_team_score,
I have this game where balloons are coming from bottom and player has to
I have this game with some variety of textures. Whenever I draw a texture
I'm making this game where I'm trying to pair people. So I have this
I have found this line of code in a game that I study int
I have found this macro while digging in the source code of tweejump game.
I have a problem with my activity. This is my onCreate: case NORMAL: game
I am not sure how to really word this, but I have a game

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.