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
Difference between report and query parameter. Why do we need different type of parameter?
If we delete pack Spec what will be the status of pack Body ?
What are trace flags?
What is triggers and its types?
What are the steps you can take to avoid “deadlocks”?
What are indexes in sql?
What is the order by used for?
What is the default Port No on which SQL Server listens?
What is sqlcmd?
You have a table with close to 100 million records recently, a huge amount of this data was updated now, various queries against this table have slowed down considerably what is the quickest option to remedy the situation?
Explain important index characteristics?
Is it possible to replicate data from sql server to oracle? : sql server replication
What is optimization and its types?
What is the difference between a unique key and primary key?
Differentiate sql server reporting services vs. Crystal reports?