Python SQL MIN() & MAX(): Finding Extremes Across Types
`MIN()` returns the lowest value and `MAX()` returns the highest value in a column or expression. They operate seamlessly across numerical amounts, alphabetical text strings (A to Z), dates, and timestamps.
"`MIN()` is finding the shortest person or earliest timestamp in a room; `MAX()` is finding the tallest person or most recent event."
Deep Dive: How It Works
Type Support: Numerical (lowest/highest numbers), Date/Time (`MIN(created_at)` = oldest record, `MAX(created_at)` = newest record), Text (`MIN(name)` = alphabetically first name).
Index Optimization: If the column is indexed with a B-Tree, `SELECT MIN(col)` and `SELECT MAX(col)` execute in O(1) instantaneous time by jumping directly to the left-most or right-most leaf node.
Subquery Pattern: Finding the full row holding the max value: `SELECT * FROM products WHERE price = (SELECT MAX(price) FROM products)`.
Syntax Blueprint
SELECT MIN(price) AS cheapest, MAX(price) AS most_expensive FROM products; -- Find newest user registration: SELECT MAX(registered_at) AS latest_signup FROM users;
Use MIN and MAX to discover lowest and highest values across data types.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Writing `SELECT name, MAX(price) FROM products` expecting the name belonging to the highest price product.Why it happens: Without subqueries or GROUP BY, SQL returns the max price paired with an arbitrary name.
How to fix: Use `WHERE price = (SELECT MAX(price) FROM products)` or `ORDER BY price DESC LIMIT 1`.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Query Min and Max Prices
Select `MIN(price) AS min_p`, `MAX(price) AS max_p` from `catalog`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.