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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:36:53+00:00 2026-06-04T17:36:53+00:00

do you know when you have that huge log table and you just need

  • 0

do you know when you have that huge log table and you just need to see the last X rows to know what is going on at the time?

usually you can do:

select top 100 * 
from log_table
order by ID desc

to show the 100 newest records, but it will do on the inverse order (of course, because of the order by DESC), for example:

100010
100009
100008
and so on..

but for the sake of simplicity I would like to see the records on the order they happened.
I can do that by running this query:

select * 
from(
    select top 100 * from log_table order by ID desc
    ) a
order by a.id

where I get my top 100 order by ID desc and then invert the result set.
It works but it seems kin of unnecessary to run 2 select to produce this result.

My question is: does anyone have a better idea of doing that? Like a select top on the end of the table?

EDIT:
execution plan of both queries:
It seems like Alex’s idea is very good but David was also right, there is only one select and one sort
enter image description here

EDIT2:
set statistics IO ON:

(10 row(s) affected)
Table 'sysdtslog90'. Scan count 1, logical reads 3, physical reads 0, read-ahead reads 0, lob logical reads 12, lob physical reads 0, lob read-ahead reads 0.

(1 row(s) affected)

(10 row(s) affected)
Table 'sysdtslog90'. Scan count 2, logical reads 5, physical reads 0, read-ahead reads 0, lob logical reads 12, lob physical reads 0, lob read-ahead reads 0.

(1 row(s) affected)
  • 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-04T17:36:54+00:00Added an answer on June 4, 2026 at 5:36 pm

    If id is indexed and sequential enough the fastest way is probably;

    select * from log_table where id > (select max(id) from log_table) - N
    

    An explicit order by is still required to guarantee the order however.

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

Sidebar

Related Questions

I know that if i have rootViewController that start with tabBar i can create
I have code that uses jquery.slideup and jquery.slidedown How can i know that div
Does anyone know do there have any way that I can encrypt the array
I know I have that my connection to the database works, and a test
I have ten or more(i don't know) tables that have a column named foo
In my application, I have several components that have to know about each other,
I know that exceptions have a performance penalty, and that it's generally more efficient
I know that i have to dispose all unmanaged resources in a class or
Does anyone know there have any other way that (by not using json_encode and
I know we have ILdasm, but is there any tool out there that will

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.