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

select top 3 * from tablename
order by 1 desc

By
Kumar Junior Software Engineer

Is This Answer Correct ?    13 Yes 6 No

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

Answer / vijaykumar dolli

Select * From Sample Where
Srno In (Select Top 3 srno From Sample Order By 1 Desc)

-- Sample is a Table Name and Srno is Unique Key column
-- This is the perfect Answer ...!

Is This Answer Correct ?    2 Yes 1 No

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

Answer / grace

SELECT TOP 3 * FROM <TABLE_NAME> WHERE <CONDITION> ORDER BY
<COLUMN_NAME> DESC

Is This Answer Correct ?    3 Yes 2 No

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

Answer / krishna sandeep

select top 3 <column_name> from ,table_name> order by
<column_name> desc

this will work.

Is This Answer Correct ?    2 Yes 2 No

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

Answer / balaji

select * from table_name ORDERBY id DESC limit 0,n;

Is This Answer Correct ?    0 Yes 0 No

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

Answer / teja

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

Is This Answer Correct ?    0 Yes 0 No

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

Answer / amit kaishver

Select * from ( select rownum k,g.* from nbfc_bank_m g) h,
(select max(rownum) a,max(rownum)-1 b,max(rownum)-2 c
from nbfc_bank_m ) p
where h.k in (p.a,p.b,p.c)

Is This Answer Correct ?    5 Yes 6 No

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

Answer / priya

select top 3 from <table name > where < specify any
condition> order by <column ID> desc

Is This Answer Correct ?    15 Yes 16 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 * 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 ?    2 Yes 3 No

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

Answer / kumar

You will be do following things one by one in sql server.

first create table.

1.create table tablename(sno int identity(1,1) primar key,
names varchar(100))

insert the record one by one.

2.
Insert into tablename(names) values ('arun')
Insert into tablename(names) values ('arun')
Insert into tablename(names) values ('arun')
Insert into tablename(names) values ('arun')
.
.
.
.
To Insert 1000 record one by one.

Then to execute the following query to get last 3 record.

select top 3 * from tablename
order by 1 desc


you will be get the correct answer ok.

By
kumar

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More SQL Server Interview Questions

What are indexes? When do you need to create Indexes?

4 Answers   CarrizalSoft Technologies, HP,


How to list all triggers in the database with sys.triggers in ms sql server?

0 Answers  


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

0 Answers  


Explain go command in sql server?

0 Answers  


What is replication with database mirroring? : sql server database administration

0 Answers  






How to change the password of a login name in ms sql server?

0 Answers  


What is the difference between stored procedure and functions?

0 Answers   MCN Solutions,


What is the differecne between equi-join and inner-join and natural join..Is there any difference or all are same?

8 Answers   Microsoft,


Write a program to fetch first 10 records from a file?

0 Answers   Amdocs,


How To delete duplicate record from a particular table?

12 Answers   eXensys, Foxfire,


What are primary keys and foreign keys?

3 Answers  


can you any body tell me while running BCP Out in instance in sql server 2000 is getting error. Error = [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.?

1 Answers  


Categories