SQL MAX Function

·

·

,

The SQL MAX function returns the largest value within a table or group. In this section, we’ll use the HumanResource.Employee table for our examples: 

Data used for SQL MAX example

Using the data above, MAX calculates the largest SickLeaveHours amount for the entire table: 

SELECT MAX(sickleavehours) MaxSickLeaveHours FROM HumanResources.Employee
SELECT MAX(sickleavehours) MaxSickLeaveHours 
  FROM HumanResources.Employee 

When used with GROUP BY, MAX returns the largest value within a group. You can see this in this query showing the maximum SickLeaveHours by JobTitle: 

SELECT JobTitle , MAX(sickleavehours) AS MaxSickLeaveHours FROM HumanResources.Employee GROUP BY JobTitle ORDER BY JobTitle;
SELECT JobTitle 
 , MAX(sickleavehours) AS MaxSickLeaveHours 
FROM HumanResources.Employee 
GROUP BY JobTitle 
ORDER BY JobTitle;

Additional SQL MAX Resources  

To learn more, check out these useful resources: 

Table Of Contents

Add a header to begin generating the table of contents


More from the blog


MySQL PostgreSQL SQLite SqlServer