View Single Post
  #7 (permalink)  
Old 06-22-2007, 09:58 PM
Unregistered
 
Posts: n/a
Default ANY answer. Re: How to find second highest value of a column in a table?

This will get you only the second max salary row
[sql]
SELECT * FROM EMP
WHERE SAL IN (SELECT MAX(SAL) FROM EMP
WHERE SAL <> (SELECT MAX(SAL) FROM EMP)) [/sql]

from how to find second largest number through a query in sql - Community Forums - Developer Fusion, the UK developer community - VB, ASP, C#, .NET, PHP and XML tutorials & source code
[sql]
select * from tmp_table m1
where (n-1)=(select count(distinct(m2.age))
from tmp_table m2 where
m2.age>m1.age)[/sql]
Reply With Quote