ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
wat will be the sql query to extract only last 3 records 
from table supose table hving thousands for records
 Question Submitted By :: Nidhi
I also faced this Question!!     Rank Answer Posted By  
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 1
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 ?    2 Yes 4 No
Amit Kaishver
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 2
select top 3 from <table name > where < specify any
condition> order by <column ID> desc
 
Is This Answer Correct ?    7 Yes 8 No
Priya
 
 
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 3
select * from emp
minus
select * from emp where rownum<(select count(*)-2 from emp)
 
Is This Answer Correct ?    2 Yes 7 No
Nitesh Srivastava
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 4
select column_name from table_name 997,1000
 
Is This Answer Correct ?    0 Yes 8 No
Varun
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 5
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 ?    1 Yes 4 No
Pawan K. Dubey
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 6
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 ?    0 Yes 4 No
Tulasi Ravi Kumar
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 7
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 ?    0 Yes 1 No
Tulasi Ravi Kumar
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 8
select top 3 * from tablename 
order by 1 desc

By
Kumar Junior Software Engineer
 
Is This Answer Correct ?    5 Yes 1 No
Kumar
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 9
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 1 No
Arun Kumar K S
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 10
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 ?    0 Yes 1 No
Kumar
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 11
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
Kumar
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 12
select top 3 <column_name> from ,table_name> order by 
<column_name> desc

this will work.
 
Is This Answer Correct ?    2 Yes 1 No
Krishna Sandeep
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 13
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 ?    1 Yes 1 No
Vijaykumar Dolli
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 14
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 1 No
Bobby
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 15
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 1 No
Shubhra
 
  Re: wat will be the sql query to extract only last 3 records from table supose table hving thousands for records
Answer
# 16
SELECT TOP 3 * FROM <TABLE_NAME> WHERE <CONDITION> ORDER BY 
<COLUMN_NAME> DESC
 
Is This Answer Correct ?    3 Yes 2 No
Grace
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
How do you find the error, how can you know the number of rows effected by last SQL statement?  1
hi, how to match retrieve the unmatched records from 2 tables in which we dont have any primary key. example : table1 has 1,2,3,4,5 and table2 has 1,2,3,4,5,6,7,8,9,10 and i want the numbers from 6 to 10 to be displayed and should not come as null. i need the numbers. please reply as soon as possible.  2
What do u mean by orphan users, how will u list them in the DB IBM2
Difference Between varchar and nvarchar datatype? Satyam2
What is user stored procedure & it purpose? Wipro3
Can we have more than one NULL in a column having unique constraint? 247Customer7
How do you check the performance of a query and how do you optimize it?  1
How to retrieve data from log files in SQL SERVER ?????  1
What are the steps you will take, if you are tasked with securing an SQL Server? HCL1
What is the difference between the following two sql statements select count(*) from <tablename> select count(col_name) from <tablename> 247Customer2
What are the different ways of moving data/databases between servers and databases in SQL Server? HCL2
What are the authentication modes in SQL Server?  2
I have to display ten columns values from diffrent ten tables. how many joins are require? HCL8
What are cursors? Name four types of cursors and when each one would be applied? Adea-Solutions1
HOW TO RENAME A COLUMN NAME  2
what is advantages in sql 2005 over sql 2000?  4
We create an index to fast the search. How it fast the query? Do we write any special keyword with query?  3
Rate yourself in .NET and SQL ? Cognizent1
explain different types of jions with examples briefly? Zensar3
how insert selected column only ? Robert-Half2
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com