wat will be the sql query to extract only last 3 records
from table supose table hving thousands for records
Answer Posted / shubhra
This query will give last three record in the table in the
same order.
CREATE TABLE dbo.Test1 (
[ID] [int] ,
[FirstName] [varchar](25),
[LastName] [varchar](25)
) ON [PRIMARY]
INSERT INTO Test1 VALUES(1, 'Bob','Smith')
INSERT INTO Test1 VALUES(2, 'Dave','Jones')
INSERT INTO Test1 VALUES(3, 'Karen','White')
INSERT INTO Test1 VALUES(1, 'Bob','Smith')
INSERT INTO Test1 VALUES(4, 'Bobby','Smita')
select identity(int,1,1) as SlNo,* into #temp from Test1
select * from (select top 3 * from #temp order by slno
desc) a order by slno
drop table #temp
Is This Answer Correct ? | 1 Yes | 2 No |
Post New Answer View All Answers
Explain what are the events recorded in a transaction log?
What is exclusive locks?
How do you make a trace?
explain declarative management framework (dmf) in sql server 2008?
How many replicas are maintained for each sql azure db?
What is an inner join?
How to integrate the ssrs reports in application?
What is the order by used for?
How to connect to SQL Azure Database by using sqlcmd?
Which table keeps information about stored procedures?
Can you always create a cache of a report?
What are window functions in sql server?
What command would you use to add a column to a table in sql server?
How to get a list of columns using the "sp_help" stored procedure in ms sql server?
What is normalization? Describe its different types.