๐Ÿ“ What Youโ€™ll Learn

  • What MIN() and MAX() functions do
  • Syntax and structure
  • Practical examples with numbers and dates
  • Use cases with GROUP BY

๐Ÿ” What Are MIN and MAX?

  • MIN() returns the lowest value in a column
  • MAX() returns the highest value in a column

These are aggregate functions, meaning they work on a set of values and return a single result.

๐Ÿงฑ Basic Syntax

SELECT MIN(column_name) FROM table_name;

SELECT MAX(column_name) FROM table_name;

You can also use them alongside WHERE, GROUP BY, and other clauses.

๐Ÿงช Example: Using MIN and MAX

Find the lowest price in the products table

SELECT MIN(price) AS lowest_price
FROM products;

Find the most expensive product

SELECT MAX(price) AS highest_price
FROM products;

๐Ÿงช Example: Dates

Get the first and last registered user by date

SELECT MIN(signup_date) AS first_signup,
       MAX(signup_date) AS last_signup
FROM users;

๐Ÿ“Œ Example with GROUP BY

Get the highest salary per department

SELECT department, MAX(salary) AS top_salary
FROM employees
GROUP BY department;

๐Ÿ“˜ Recap

  • MIN() gives the smallest value; MAX() gives the largest
  • Work with numbers, dates, and text (alphabetically)
  • Useful for reporting, summaries, and comparisons
  • Combine with GROUP BY for segmented analysis