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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:33:53+00:00 2026-06-07T03:33:53+00:00

I need to select min ID value from top 5 rows in the table.

  • 0

I need to select min ID value from top 5 rows in the table. I get top IDs with this query:

SELECT id FROM items ORDER BY id DESC LIMIT 5

It works fine and returns ID values from top 5 rows:

314
313
312
311
310

Now, trying to get the minimal ID from this set:

SELECT MIN(id) FROM items ORDER BY id DESC LIMIT 5

I expect the result to be 310 but SQLite return 1.
What’s up with that? Where am I wrong and do I achieve my goal?

UPDATE:

SELECT MIN(id) FROM (SELECT id FROM news_items ORDER BY id DESC LIMIT 5) works, so now I’m just curious about what’s wrong with the first query.

  • 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-07T03:33:55+00:00Added an answer on June 7, 2026 at 3:33 am

    Assuming that you are actually using MIN instead of MAX, then the explanation is very simple. The ORDER BY id DESC LIMIT 5 is the last part that gets evaluated on your query. So, on your first query, you are retrieving the minimum value for id (it should be 0), then the ORDER BY .... is irrelevent (you are ordering and limiting just one row)

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

Sidebar

Related Questions

I need to select only 20 records from the table and than add pagination
I have about the following query: SELECT * FROM Product ORDER BY (SELECT CASE
SELECT Id, Value, Sender, Recipient, MIN(DateTime), TypeOf, VideoId, Likes, Comments FROM xx.dbo.StreamView WHERE StreamView.TypeOf
I'm trying to get the MIN value from both tables (one return value). Following
Alright I have a table where I need to get the relevant date from
I would need to get an average from the below linq query but the
I have a problem where I need to get the earliest date value from
I have a query like this: SELECT Weighings.Member, MIN(Sessions.DateTime) AS FirstDate, MAX(Sessions.DateTime) AS LastDate
I need to quickly select a value ( baz ) from the earliest (
I need to select elements of a certain class except children of $(this). The

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.