Pages

Thursday, May 27, 2010

SQL Query: Second Maximum/Second Minimum

Tip to find the first max/min is predefined but what about second. Here is one of the tip for well known table employee

Second maximum salary
Select max(salary) from employees where regid NOT IN
(Select max(salary) from employees)

Second minimum salary
Select min(salary) from employees where regid NOT IN
(Select min(salary) from employees)