GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — SQL MAX() Function - GeeksforGeeks SQL MAX() FunctionLast Updated : 22 Nov, 2025 The SQL MAX() function helps quickly identify the highest value within any column, making it useful for summarizing and analyzing data trends. It is widely used in reports to find top values like peak sales, latest dates, or highest scores.
Example: First, we create a demo SQL database and table, on which we use the MAX() functions. ![]() Query: SELECT MAX(Price) AS HighestPrice Output: ![]()
Syntax: SELECT MAX(column_name) Examples of SQL MAX() FunctionHere, we demonstrate the usage of the MAX() function using a single sample table named Products. Consider this Products table for all the examples below: ![]() Example 1: Find the Maximum Price in a TableIn this example, we see how the MAX() function retrieves the highest total_sales value from the Products table while ignoring NULL values. Query: SELECT MAX(total_sales) AS [Highest Total Sales] Output: ![]()
Example 2: Use MAX() with a ConditionIn this example, we see how the MAX() function returns the highest price after filtering rows based on a specific condition. Query: SELECT MAX(price) AS [Highest Price in Electronics] Output: ![]()
Example 3: Find the Latest Sale DateIn this example, we use MAX() to get the most recent sale date from the table. Query: SELECT MAX(sale_date) AS [Latest Sale Date] Output: ![]()
Example 4: Using MAX() with GROUP BYIn this example, we use MAX() with GROUP BY to find the highest sale amount for each product. Query: SELECT product_name, MAX(total_sales) AS [Top Sales Amount] Output: ![]()
Example 5: Using MAX() in SubqueriesIn this example, we use MAX() inside a subquery to get the product with the highest total_sales. Query:
Output: ![]()
Example 6: Using MAX() with HAVINGIn this example, we use MAX() with HAVING to filter product groups based on their highest total sales. Query: SELECT product_name, MAX(total_sales) AS HighestSale Output: ![]()
Comment ExploreData Constraints & Aggregate Functions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |