Home  >  Forum  >  Database
Post New Query

Query/command to select second max value in a list using sql


joined on
October 10,2013
Asked on September 15,2014
I am learning the oracle database using sql. I have a list that i want to display the second max value from the given list, please tell what query may I use?
joined on
March 15,2013
Replied on September 15,2014

SQL> select max(value) from table_name where value NOT IN (select max(value) from table_name);
Or use can use <> operator instead of NOT IN

SQL> select max(value) from table_name where value <> (select max(value) from table_name);
both query are correct
joined on
October 10,2013
Replied on September 15,2014

Thanks Atul, but I have one more problem that I have a list where second max value in 3, in this case it will show the one one. But I want do display name and other for those row that have second max value?
joined on
March 15,2013
Replied on September 16,2014

Okay so you want to display the name of those who have second max value.

SQL>select name from table_name where value IN (select max(value) from table_name where value <> (select max(value) from table_name));

Write Answer



Sitewide-Feb4of4234x60





Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us