Introduction
MIN and MAX help find the smallest or largest value in a list of data. They make it easy to spot extremes.
MIN and MAX help find the smallest or largest value in a list of data. They make it easy to spot extremes.
SELECT MIN(column_name) FROM table_name; SELECT MAX(column_name) FROM table_name;
Use MIN to get the smallest value in a column.
Use MAX to get the largest value in a column.
SELECT MIN(price) FROM products;
SELECT MAX(score) FROM game_scores;
SELECT MIN(birthdate) FROM users;
SELECT MAX(salary) FROM employees;
This example creates a sales table, adds some sales amounts, then finds the smallest and largest sale.
CREATE TABLE sales ( id INT, amount DECIMAL(10,2) ); INSERT INTO sales VALUES (1, 100.50), (2, 250.00), (3, 75.25), (4, 300.00); SELECT MIN(amount) AS LowestSale, MAX(amount) AS HighestSale FROM sales;
MIN and MAX ignore NULL values automatically.
You can use these functions with numbers, dates, and even text (alphabetically).
MIN finds the smallest value in a column.
MAX finds the largest value in a column.
They help quickly find extremes in your data.
MIN function do in MySQL?price column of a table named products?employees with a column salary containing values (3000, 4500, 2500, 5000), what will this query return?SELECT MIN(salary), MAX(salary) FROM employees;users table?SELECT MIN age FROM users;orders with columns order_id, customer_id, and amount. How would you write a query to find the highest order amount for each customer?Pass the test and this pattern moves unknown