Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (55.6k points)

Can anyone explain how to get the last 5 records in SQL?

1 Answer

0 votes
by (119k points)

Here is the syntax to get the last 5 records of the table in SQL:

SELECT * FROM

                (SELECT TOP 5 *

FROM table_name

                ORDER BY ID DESC

                )

ORDER BY id ASC;

In the above query, we used subquery with the TOP clause that returns the table with the last 5 records sorted by ID in descending order. Again, we used to order by clause to sort the result-set of the subquery in ascending order by the ID column.

If you want to take a course that can provide Instructor-led training and certification, I suggest this SQL Training by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
asked May 7, 2020 in SQL by Sudhir_1997 (55.6k points)
0 votes
1 answer

Browse Categories

...