Select Max in SQL
? SELECT MAX() in SQL
The MAX() function returns the maximum value from a column in a table. It is commonly used to find the highest numeric value, latest date, or maximum string in a dataset.
? Syntax:
SELECT MAX(column_name) FROM table_name WHERE condition;? Examples:
Find the highest salary in employees table:
SELECT MAX(salary) AS highest_salary FROM employees;Find the latest order date:
SELECT MAX(order_date) AS last_order_date FROM orders;Find the maximum product price in a category:
SELECT MAX(price) AS max_price FROM products WHERE category = 'Electronics';? Notes:
Works on numeric, date/time, and string columns.
Returns a single scalar value.
Can be used with
GROUP BYto find maximums per group:
SELECT department, MAX(salary) AS max_salaryFROM employeesGROUP BY department;If you want, I can show examples of MAX() with GROUP BY or in complex queries!