11,935,053 members (56,587 online)
Rate this:
See more:
I want to know the query for selecting the latest 25 rows from a table. ...plzz help me to do it.
Posted 13-Oct-12 3:36am

"plzz" is on vacation this week. Sort the result set descending and then get the top 25.
Maciej Los 15-Oct-12 16:28pm

My virtual 5!

Rate this:

## Solution 1

I assume that you are deciding latest 25 based on a date..

`SELECT TOP 25* FROM TABLENAME order by DATECOLUMNNAME DESC`
v2
Rate this:

## Solution 2

solution 1 will also give you the correct result but it will be a little slow in case of many records

here is an example

```SELECT ORDERID, CUSTOMERID, OrderDate

FROM

(

SELECT ROW_NUMBER() OVER (PARTITION BY EmployeeID ORDER BY OrderDate DESC) AS OrderedDate,*

FROM Orders

) as ordlist

WHERE ordlist.OrderedDate <= 25```
Rate this:

## Solution 3

First you should have a column in Tables named as (Last_Updated or Recent_Visit) in datetime datatype.
That column should fill with datetime of the current timing Eg - Getdate()
Dont convert the datetime of getdate(), because you cant get latest one.

Query Below:

`Select top 25 * from MyDB..MyTable with (Nolock) order by Recent_Visit desc`
v2
Rate this:

## Solution 4

```create table emp(emp_id int identity,emp_name varchar(20),registerationtiming varchar(20))

Select top 25 * from emp order by registerationtiming desc ```

Top Experts
Last 24hrsThis month
 George Jonsson 450 Sergey Alexandrovich Kryukov 342 Kornfeld Eliyahu Peter 230 Dave Kreskowiak 229 Richard Deeming 225
 George Jonsson 450 Sergey Alexandrovich Kryukov 342 Kornfeld Eliyahu Peter 230 Dave Kreskowiak 229 Richard Deeming 225