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)
 how to find n th max in oracle

Author  Topic 

dasu
Posting Yak Master

104 Posts

Posted - 2004-10-10 : 04:13:48
please suggest me the solution for how to get 3rd maximum in a table mssqlserver with out using top
regards
dasu.g

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-10-10 : 11:39:45
like this:
this will return 3rd max salary from employees

declare @n int
set @n = 3 -- n-th value tp get
Select *
From Employee E1
Where (@n-1) = (Select Count(Distinct(E2.Salary)) From Employee E2 Where E2.Salary > E1.Salary)

hope it helps.

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

- Advertisement -