SQL MAX
The MAX() function is an aggregate function used to find the largest (maximum) value in a column.
👉 In simple terms:
MAX() returns the highest value from a column.It works with numbers, dates and text values (alphabetically last)
Important Points:
1️. MAX() returns the largest value in a column
2️. Works with numbers, dates, and text
3️. NULL values are ignored
4️. Often used with GROUP BY
Syntax
SELECT MAX(column_name) FROM table_name;
MAX Example: Find the maximum price.
SELECT MAX(Price) AS MaximumPrice FROM Orders;
MAX with WHERE: Find the maximum price where Quantity > 2
SELECT MAX(Price) AS MaximumPrice FROM Orders WHERE Quantity > 2;
MAX with GROUP BY: Find the maximum quantity for each customer.
SELECT CustomerID, MAX(Quantity) AS MaximumQuantity FROM Orders GROUP BY CustomerID;
Simple Definition (Exam/Interview):
MAX() is an SQL aggregate function used to return the highest value from a specified column in a table.