Get the second highest value in a column

Here are step-by-step instructions to get the second highest value in a column.

I recently had the need to retrieve the second highest value in a column. Here are the steps I used:

 
  
select
  max(SALARY)
from
  EMPLOYEE
where
  SALARY < (select max(SALARY) from EMPLOYEE)

Note -- If you want the entire record, try this:

select * from EMPLOYEE where SALARY = (
   select
     max(SALARY)
   from
     EMPLOYEE
   where
     SALARY < (select max(SALARY) from EMPLOYEE)

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Visit the ITKnowledge Exchange and get answers to your developing questions fast.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.


This was last published in July 2005

Dig Deeper on Data backup, storage and retrieval on iSeries

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchEnterpriseLinux

SearchDataCenter

Close