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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:18:12+00:00 2026-05-30T14:18:12+00:00

Im trying to get a result set that contains the 10 values that are

  • 0

Im trying to get a result set that contains the 10 values that are closest to, in this case, the number 3.

I have a database that has values in a column named rated which can be 1,2,3,4 or 5. What im trying to do is query the database and return the first 10 rows that have the values closest to 3. The values can be above 3 or below 3. I should note that these values in the rated column are floats.

I then need to sort these rows in order so that rows with value of 3 are first and then the row with lowest offset (+/-) from 3.

Is there any SQL query that can return atleast the result set of values closest to 3 ? or am i going to have to return the whole db and sort it myself?

To get the first 10 rows with highest value down i used the statement

SELECT * FROM tabs ORDER BY 5 DESC LIMIT 10";

5 refers to the column rated

Is there some way to modify this to do what i want ?
Thanks

  • 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-30T14:18:13+00:00Added an answer on May 30, 2026 at 2:18 pm

    If I understand your problem correctly, this should do the trick:

    select *
    from tabs
    order by abs(`rated` - 3) asc
    limit 10
    

    Note that it sorts by the difference in ascending order, so those with a difference of 0 will come first.

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

Sidebar

Related Questions

I'm trying to convert json result to set of objects, but i get an
I'm trying to get the result of a COUNT as a column in my
I have a 3 tables that I'm trying to join and get distinct results.
I have a list that contains groups of nearly identical numeric values. i.e. (1004.523,
I'm trying to set attribute value that contains a single quote: var attr_value =
I'm trying to get a result of FOR XML query as a text. I've
I have an issue when trying to get Javascript to execute functions in my
I am trying to query for Objects that match ALL of a given set
I've got a Core Data property that I'm trying to set at runtime, with
I have a view which contains a users id and an image column. Here's

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.