Write a query to fetch top N records

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

SELECT name, marks
FROM students
ORDER BY marks DESC
LIMIT 3;
Tutorials Class - Output Window
name marks
Maria 92
Asha 88
Robin 85

Change the number after LIMIT to get the top N. For the lowest N use ORDER BY marks ASC. See MySQL LIMIT.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.