How to select nth record from a table?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
What do you understand by the denormalisation?
What is a NOLOCK?
What is field with example?
How can you control the amount of free space in your index pages?
Explain powershell included in sql server 2008?
Can we insert data into a view?
how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,...
7 Answers ADP, Satyam, Tech Mahindra,
How many triggers you can have on a table?
Explain the benefits of user-defined functions?
Distinguish between nested subquery and correlated subquery?
How to list all login names on the ms sql server?
What is onf in normalization form?