Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Give me the query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-08-25 : 18:59:09
srinivasan A.K writes "

1. i want to find out the 5 th row in a table. what is the qurey for that
2. i want to select 5 th highest salary in a salary table. what is the query for that

thanks
srinivasan


"

chadmat
The Chadinator

1974 Posts

Posted - 2004-08-25 : 19:16:49
USE Northwind
GO

select min(EmployeeID)
from (select top 5 Employeeid from employees order by EmployeeID desc) a

-Chad

http://www.clrsoft.com

Software built for the Common Language Runtime.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-26 : 04:34:36
5th highest salary:

declare @n int
set @n = 5 -- number of highest salary to get
Select *
From Employee E1
Where (@n-1) = (Select Count(Distinct(E2.Salary)) From Employee E2 Where E2.Salary > E1.Salary)

same can be also used for 5th row. but 5th row is a relative term. it depends on your order by column, becasuse there is no order as such in the way the data is stored in sql server

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page
   

- Advertisement -