Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 is the difference between TRUNCATE and DROP?

0 Answers  


How you can get a list of all the table constraints in a database?

0 Answers  


what is the query and condition to delete datas in sql server.

2 Answers  


What is the difference between a Local temporary table and a Global temporary table? How is each one used?

2 Answers   HCL,


What are the differences between clustered and non-clustered index?

0 Answers  


your distribution database is full what will u do

0 Answers  


How to implement one-to-one, one-to-many and many-to-many relationships while designing tables?

0 Answers  


How can i change the column name.

13 Answers   HCL, Yardi Software,


How to add additional conditions in SQL?

0 Answers   Amdocs,


What is the preferred way to create a clustered and non-clustered index? Which index should you create first the clustered or non-clustered?

0 Answers  


Do you know exporting and importing utility?

0 Answers  


What are sp_configure commands and set commands?

0 Answers  


Categories