How to find the second highest marks in MySQL?

The examples use the students table from our MySQL tutorial: id, name, city, marks, course_id.

-- 1. with a subquery
SELECT MAX(marks) AS second_highest
FROM students
WHERE marks < (SELECT MAX(marks) FROM students);

-- 2. with LIMIT and OFFSET
SELECT DISTINCT marks
FROM students
ORDER BY marks DESC
LIMIT 1 OFFSET 1;
Tutorials Class - Output Window
second_highest
88

The highest marks are 92 (Maria), so the second highest is 88 (Asha). For the Nth highest, change the OFFSET to N – 1. See Subqueries.


Learn more about the similar topics:
Tutorials
MySQL JOINs
MySQL Subqueries
MySQL UNION
Exercises & Assignments
Write a query to show the student name who has the second highest marks
Write a query to show the names of students with their course names
Write a query to count the students of each course, including empty courses
Write a query to find the students who scored above the average marks
Interview Questions & Answers
What is the difference between INNER JOIN and LEFT JOIN?
What is the difference between UNION and UNION ALL?
What are the types of JOINs in MySQL?
How to find the second highest marks in MySQL?
What is a subquery in MySQL?