- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the 2nd highest value from a table with Student Score?
To fetch the 2nd highest value, use ORDER BY DESC with LIMIT 1,1. Let us first create a table −
mysql> create table DemoTable ( StudentScore int ); Query OK, 0 rows affected (0.56 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(69); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(97); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(99); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------------+ | StudentScore | +--------------+ | 89 | | 69 | | 97 | | 99 | +--------------+ 4 rows in set (0.00 sec)
Following is the query to get the 2nd highest value −
mysql> select *from DemoTable order by StudentScore DESC limit 1,1;
This will produce the following output −
+--------------+ | StudentScore | +--------------+ | 97 | +--------------+ 1 row in set (0.00 sec)
- Related Articles
- How to get the data from a specific cell value (say 2nd row and 2nd column) inside a table in Selenium with python?
- Get the highest score value from a single column and the greatest from two columns in MySQL
- C++ code to find rank of student from score table
- MySQL query to get first two highest column values from a table?
- Smallest Rotation with Highest Score in C++
- How to get the fourth highest value using MySQL query?
- Change the column name from a MySQL table with Student record?
- How to display highest value from a string with numbers set as varchar in MySQL?
- How to Find a P-Value from a t-Score in Python?
- How To Find A P-Value From A Z-Score In Python?
- How to retrieve the value from a table cell with TableModel in Java?
- How to order by the highest value from two columns in MySQL?
- Java Program to get the lowest and highest value in TreeSet
- How to delete a single value from a MySQL table with duplicate records?
- MySQL order by from highest to lowest value?

Advertisements