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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:29:54+00:00 2026-06-18T05:29:54+00:00

I have a table (Article), it has 10 records, I want to get the

  • 0

I have a table (Article), it has 10 records, I want to get the last four records (6th, 7th, 8th, 9th) without 10th. The Query may also work for more than 10 records to get the last four rows without the absolute last one.
Thanks in Advance!

  • 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-18T05:29:55+00:00Added an answer on June 18, 2026 at 5:29 am

    In SQL, tables are inherently unordered. So, let me assume that you have a column that specifies the ordering — an id column, a date time, or something like that.

    The following does what you want:

    select top 4 *
    from (select top 5 *
          from Article a
          order by id desc
         ) a
    order by id asc
    

    If for some reason you don’t have an id, you can take your chances with the following query:

    select a.*
    from (select a.*, row_number() over (order by (select NULL)) as seqnum,
                 count(*) over () as totcnt
          from Article a
         ) a
    where seqnum between totcnt - 5 and totcnt - 1
    

    I want to emphasize that this is not guaranteed to work. In my experience, I have seen that definition of seqnum assign sequential number to rows in order. BUT THIS IS NOT GUARANTEED TO WORK, and will probably not work in a multi-threaded environment. But, you might get lucky (particularly if your rows fit on one data page).

    By the way, you can use the same idea with a real column:

    select a.*
    from (select a.*, row_number() over (order by id) as seqnum,
                 count(*) over () as totcnt
          from Article a
         ) a
    where seqnum between totcnt - 5 and totcnt - 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that has multiple duplicate records as the following: ID Title
I have a table Article which has one column keywords which stores tags or
I have a table articles that has a column company which has list of
I have a simple cakephp app with table articles that has a cat_id column
Lets say I have a table in MySQL called articles, that has a column
I have an table Article that is in relationship with Steps (OneToMany) and Steps
I have one table, e.g. pricerules, that have stored special prices by article for
I want to fetch some data from the following database table 'article'. i want
Background: entities tables currently has 14,111 records articles table currently has 5211 records I
I have a table with an embedded picture(OLE) coulmn. I Want to be able

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.