How to Find Rows with Maximum Value Database: SQL PostgreSQL MS SQL Server Oracle MySQL SQLite Operators: MAX WHERE Table of Contents Problem: Example: Solution: Discussion: Problem: You want to find rows which store the largest numeric value in a given column. Example: Our database has a table named student with data in the following columns: id, first_name, last_name, and grade. You want to find the students who have the highest grades. idfirst_namelast_namegrade 1LisaJackson3 2GaryLarry5 3TomMichelin2 4MartinBarker2 5EllieBlack5 6MarySimpson4 Solution: SELECT id, first_name, last_name, grade FROM student WHERE grade = (SELECT MAX(grade) FROM student); Here’s the result: idfirst_namelast_namegrade 2GaryLarry5 5EllieBlack5 Discussion: To find the maximum value of a column, use the MAX() aggregate function. The function takes a column name or an expression to find the maximum value. In our example, we use the subquery to find the highest number in the column grade. The subquery is: SELECT MAX(grade) FROM student The main query displays ID, first and last name of the student, and their grade. To display only the rows with the maximum value among all values in the column (e.g., SELECT MAX(grade) FROM student), use WHERE with a subquery. In WHERE, put the name of the column with the comparable value to the value returned by aggregate function in the subquery. In our example it is: WHERE grade = (SELECT MAX(grade) FROM student) Recommended courses: SQL Basics SQL Practice Set Recommended articles: SQL Basics Cheat Sheet How to Practice SQL Subqueries 5 SQL Subquery Examples What Are the Different Types of SQL Subqueries? Using Subqueries in INSERT, UPDATE, DELETE Statements SQL MAX Function SQL MIN and MAX Functions Explained in 6 Examples SQL Aggregate Functions Cheat Sheet See also: How to Find the Minimum Value of a Column in SQL How to Find the Maximum Value of a Numeric Column in SQL Subscribe to our newsletter Join our monthly newsletter to be notified about the latest posts. Email address How Do You Write a SELECT Statement in SQL? What Is a Foreign Key in SQL? Enumerate and Explain All the Basic Elements of an SQL Query