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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:19:00+00:00 2026-06-03T16:19:00+00:00

This could be a very basic problem, but I sort of don’t know SQL

  • 0

This could be a very basic problem, but I sort of don’t know SQL at all.

To simplify the problem, let there be a table with only one column, so I can write down the rows horizontally:

1 3 11 39 41 45 52 63 66 70 72 80 81 90 92 97

As you can see, they are sorted. Now, I know there is the row with "70", and I want to query five rows before it in ascending order. That is, I want

41 45 52 63 66

How should I do the query?

I can query the five rows in descending order and reverse the result set afterwards, but I think there should be a better way.

  • 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-03T16:19:01+00:00Added an answer on June 3, 2026 at 4:19 pm

    Taking likeToCode’s example, just modify it as follows, to reorder the result:

    SELECT * FROM (
        SELECT *
        FROM SAMPLE
        WHERE index1 < 70
        ORDER BY index1 DESC
        LIMIT 0,5
    )
    ORDER BY index1 ASC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sorry if this is a very basic but I couldn't find anything in
Introduction: Now I know this question could be very broad and it would be
I know this could boil down to a philosophical issue, so I don't mean
I have a question that could seem very basic, but it is in a
I would be very grateful if someone could help me with this. I have
This must be very simple, but I couldn't find it on the documentation. In
This looked like a very simple question but I couldn't find the answer. How
This could be a little off the ballpark, but a friend asked me about
Perhaps this is a very basic question, please pardon me if it is ---
This may seem like a basic/stupid/obviously-answered question, but I wanted to check: why use

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.