Content
MAX and MIN find the largest and smallest values in a column. Works with numbers, dates, and strings.
Find Maximum Value
SELECT MAX(price) as highest_price FROM products;
Find Minimum Value
SELECT MIN(price) as lowest_price FROM products;
MAX/MIN with GROUP BY
SELECT category, MAX(price), MIN(price)
FROM products
GROUP BY category;
Find Latest/Earliest Date
SELECT MAX(order_date) as latest_order FROM orders;
SELECT MIN(created_at) as first_customer FROM customers;
MAX/MIN with Subquery
SELECT * FROM products WHERE price = (SELECT MAX(price) FROM products);
Combine MAX, MIN, AVG
SELECT
MIN(salary) as min_salary,
MAX(salary) as max_salary,
AVG(salary) as avg_salary
FROM employees;
Generate MAX/MIN Queries
Ask for highest or lowest values and AI2sql writes the query.


