Monday, March 5, 2007

Second Max value - query

Its often asked in interviews , "Write a query to retrive the second maximum salary from a table." , especially when we are questioned about Databases.Here is a solution...

Select max(salary) from tablename where salary not in(select max(salary) from tablename);

or

select max(salary) from tablename where salary<(select max(salary) from tablename);

No comments: