Introduction
MIN and MAX functions help find the smallest or largest value in a group of data. They make it easy to compare numbers or dates.
Jump into concepts and practice - no test required
SELECT MIN(column_name) FROM table_name; SELECT MAX(column_name) FROM table_name;
SELECT MIN(price) FROM products;
SELECT MAX(score) FROM game_scores;
SELECT MIN(birthdate) FROM employees;
SELECT MAX(salary) FROM employees WHERE department = 'Sales';
CREATE TABLE products (id INT, name VARCHAR(20), price DECIMAL(5,2)); INSERT INTO products VALUES (1, 'Pen', 1.20), (2, 'Notebook', 2.50), (3, 'Eraser', 0.80); SELECT MIN(price) AS LowestPrice, MAX(price) AS HighestPrice FROM products;
MIN() do when applied to a column of numbers?MIN() function is designed to find the smallest value in a column of data.MAX() which finds the largest, or AVG() which calculates average, MIN() specifically returns the minimum value.Employees?MAX() requires parentheses around the column name.SELECT MAX(salary) FROM Employees; uses MAX(salary) which is correct. Forms without parentheses or using [] {} are invalid.Products with a column Price containing values (100, 250, 50, 400), what will the query SELECT MIN(Price), MAX(Price) FROM Products; return?Users table?SELECT MAX age FROM Users;MAX() function requires parentheses around the column name, so MAX age is invalid syntax.Orders with columns OrderID, CustomerID, and TotalAmount. How would you write a query to find the highest order amount for each customer?CustomerID.MAX(TotalAmount) with GROUP BY CustomerID returns the maximum order amount for each customer.