Max Function In Sql in SQL
? MAX() Function in SQL
The MAX() function returns the maximum (largest) value from a set of values in a column.
? Syntax:
SELECT MAX(column_name) FROM table_name;? Example:
SELECT MAX(salary) AS highest_salaryFROM employees;Result:
| highest_salary |
|---|
| 95000 |
? Notes:
Works with numeric, date, and text (alphabetically) values.
Often used with
GROUP BYto get the max per group:
SELECT department, MAX(salary) AS top_salaryFROM employeesGROUP BY department;? Supported In:
? MySQL, SQL Server, PostgreSQL, Oracle, SQLite, and others.
Let me know if you'd like to compare MAX() with MIN() or use it in a JOIN or subquery!