wat will be the sql query to extract only last 3 records
from table supose table hving thousands for records

Answers were Sorted based on User's Feedback



wat will be the sql query to extract only last 3 records from table supose table hving thousands f..

Answer / 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

wat will be the sql query to extract only last 3 records from table supose table hving thousands f..

Answer / lakram5455

SELECT TOP(3) * FROM emp ORDER BY EId DESC

Is This Answer Correct ?    0 Yes 1 No

wat will be the sql query to extract only last 3 records from table supose table hving thousands f..

Answer / nitesh srivastava

select * from emp
minus
select * from emp where rownum<(select count(*)-2 from emp)

Is This Answer Correct ?    8 Yes 10 No

wat will be the sql query to extract only last 3 records from table supose table hving thousands f..

Answer / tulasi ravi kumar

hi this is tulasi ravi
id - ravi106109@gmail.com

select empno,sal from emp where rowid in
(select rowid from emp
minus
select rowid from emp where rownum<=(
select count(*)-3 from emp))


feel free to mail queries,,,.....

Is This Answer Correct ?    3 Yes 5 No

wat will be the sql query to extract only last 3 records from table supose table hving thousands f..

Answer / kumar

very good kumar
a sweet and simple query
i tink u can go to microsoft for work
wat a query it is
good keep it up

Is This Answer Correct ?    1 Yes 3 No

wat will be the sql query to extract only last 3 records from table supose table hving thousands f..

Answer / bobby

select * from table_name where <Primary key Column-
name> != all
(select top (@@rowcount-3) <Primary key Column-name> from
Table_name)

Is This Answer Correct ?    0 Yes 2 No

wat will be the sql query to extract only last 3 records from table supose table hving thousands f..

Answer / pawan k. dubey

1-select * from employee where emp_id >(select count(*)-3
from employee)

2-select * from employee where emp_id in
(
select top 3 emp_id from employee order by emp_id DESC

)

Is This Answer Correct ?    2 Yes 6 No

wat will be the sql query to extract only last 3 records from table supose table hving thousands f..

Answer / arun kumar k s

drop table #temp select identity(int,1,1) as SlNo, * into
#temp from TABLE_NAME select top 3 * from #temp order by
SlNo desc

arun_4454@yahoo.co.in

Is This Answer Correct ?    0 Yes 4 No

wat will be the sql query to extract only last 3 records from table supose table hving thousands f..

Answer / varun

select column_name from table_name 997,1000

Is This Answer Correct ?    1 Yes 14 No

Post New Answer

More SQL Server Interview Questions

What are the difference between data mart and data warehouse? : sql server analysis services, ssas

0 Answers  


What is built-in function?

0 Answers  


What is "scheduled jobs" or "scheduled tasks"?

0 Answers  


What do you mean by stored techniques? How would we use it?

0 Answers  


I have a table EMP in which the values will be like this EmpId Ename Sal DeptId 11 Ram 10000 10 11 Ram 10000 10 22 Raj 20000 20 22 Raj 20000 20 33 Anil 15000 30 33 Anil 15000 30 I want to delete only duplicate Rows. After Delete I want the output like this EmpId Ename Sal DeptId 11 Ram 10000 10 22 Raj 20000 20 33 Anil 15000 30

13 Answers   DELL,






how to copy sysdatabase file from c: Drive to D: Drive in SQL Server.

6 Answers   IBM,


What is the maximum number of index per table?

0 Answers  


What are cursors? Explain different types of cursors. What are the disadvantages of cursors? How can you avoid cursors?

0 Answers  


Can anyone tell that the extra features are there in SQL SERVER 2008 that are not available in previous versions .

0 Answers   HCL,


After recovering the database by using tail log backup.How to verify the data has been sucessfully restored or not.?

0 Answers   Cognizant,


What is the difference between the application object and session object?

0 Answers  


What is DCL?

0 Answers  


Categories