How to select nth record from a table?

Answers were Sorted based on User's Feedback



How to select nth record from a table?..

Answer / soorai ganesh

SELECT * FROM
(
SELECT ROW_NUMBER() OVER(ORDER BY column_name) AS Rno,*
FROM Table_Name
)T
WHERE T.Rno = 7 -- If N is 7 other wise put ur nth value.

Is This Answer Correct ?    45 Yes 9 No

How to select nth record from a table?..

Answer / saravanan p

Select top 1 * from
(Select top n * from tbl order by column name asc)tbl1
order by column name desc

Is This Answer Correct ?    18 Yes 12 No

How to select nth record from a table?..

Answer / karthik

select * from (select rownum r , emp.* from emp)
where
r='&n'

Give the value of n. It will return the nth record.

Is This Answer Correct ?    13 Yes 8 No

How to select nth record from a table?..

Answer / pallavi attarde

Here N is for Nth record.

SELECT TOP 1 * FROM
(SELECT TOP N * FROM
(SELECT Table.Coloumn1,Table.Coloumn2 from Table)
as d order by d.Coloumn1 desc) as p order by Coloumn1

Is This Answer Correct ?    8 Yes 5 No

How to select nth record from a table?..

Answer / veeresh kethari

select min(sal) from EMP where sal in(select top n sal from
EMP
order by SAL desc)

Is This Answer Correct ?    3 Yes 0 No

How to select nth record from a table?..

Answer / saravanan p

select * from
(select row_number() over(order by empid) rno,* from tbl)
tbl1
where tbl1.rno=n

Is This Answer Correct ?    8 Yes 6 No

How to select nth record from a table?..

Answer / rathika

Answer #7 should be

select top 1 * from (select top n * from tbl order by col1
asc) tbl order by col1 desc

where n = nth number in the list

Is This Answer Correct ?    8 Yes 7 No

How to select nth record from a table?..

Answer / roxy

select top 1 * from (select top n * from tbl order by col1
desc) tbl order by col1 asc

where n = nth number in the list

Is This Answer Correct ?    5 Yes 5 No

How to select nth record from a table?..

Answer / andy

select a.id,a.name from dept a
where
1= (select COUNT(b.id) from dept b where b.id>a.id)

Is This Answer Correct ?    4 Yes 4 No

How to select nth record from a table?..

Answer / mohan krishna

declare @querry nvarchar(500)
declare @row varchar(10)
set @row = '5'

set @querry ='
select top 1 a.* from
(select * from vdpmaster..usermaster
where usr_id not in
(select top '
set @querry = @querry + @row + ' usr_id from
vdpmaster..usermaster)
)a'
print @querry
EXEC sp_executesql @querry

Is This Answer Correct ?    3 Yes 4 No

Post New Answer

More SQL Server Interview Questions

Is sql server implemented as a service or an application? : Sql server database administration

0 Answers  


What command must you use to include the not null constraint after a table has already been created?

0 Answers  


After creating the cube, if we added a new column to the oltp table then how you add this new attribute to the cube? : sql server analysis services, ssas

0 Answers  


A table contains list of customers and his city with other details. Each customer has a unique number and the table consists millions of data. Query is: I want to retrieve 10 customers from each city, no script, only from single query?

8 Answers   Infosys,


What is tempdb database? : SQL Server Architecture

0 Answers  






Explain different types of Normalization.

0 Answers   HPCL, Hughes Systique Corporation, Ittiam Systems,


what is denormalization and when would you go for it? : Sql server database administration

0 Answers  


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

0 Answers  


wht's the differece between sqlserver05 and sqlserver2000

3 Answers  


Please give me the SP for the below scenario. I have two tables named Table1 and Table2...I need to fetch record by record from Table1 and insert the record in to table2 where the value in the sno column of the table1 is even number.

4 Answers   Value Labs,


SYNTAX FOR VIEWS WITH EXAMPLE HOW TO LINK TWO TABLES

1 Answers   Microsoft,


‘Order by’ is not allowed in a view how can you sort information from a view?

0 Answers  


Categories