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




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?


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



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?


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










©2024 concretepage.com | Privacy Policy | Contact Us