Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,i have to find the last 50 records in a table,i dont know how many numbers of records are there.can anybody having any idea then please help me.


thank you in advance.
Posted

Try this
SQL
select  *
from    (
        SELECT  row_number() over(order by BogusRowOrder) as RowNum,
                count(*)     over()            as RowCnt,
                *
        from    (
                SELECT  1 as BogusRowOrder,
                        *
                FROM    [AdventureWorks].[Production].[Product]
                ) as a
        ) as b
where   RowNum > RowCnt-50
 
Share this answer
 
Here is the sample query to fetch last 50 records:

SQL
select *
from Employee where empid not in (
    select top (
        (select count(*) from Employee) - 5
    ) empid
    from Employee
)
 
Share this answer
 
Comments
chinta123 28-Feb-12 9:48am    
i could n't get .can you pls elaborate it..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900