SQL MIN and MAX Functions

SQL Tutorial

Here is a clear and practical guide to the SQL MIN and MAX Functions, including examples, behavior notes, and best practices.


 What SQL MIN and MAX Functions Do

  • MIN() returns the smallest value in a column

  • MAX() returns the largest value in a column

Both work on numeric, text, and date types.


Basic Syntax


 Examples

1. Find the lowest and highest product price


2. Find oldest and newest date


3. MIN/MAX on text (lexicographical order)

Alphabetically first/last value:


 Using MIN/MAX with GROUP BY

Apply MIN/MAX per category or group:


 Important Behavior Notes

NULL values are ignored by both MIN() and MAX()
MIN/MAX work on text, numbers, dates
✔ When mixing with other columns, you must use GROUP BY


 Common Real-World Use Case

Find the earliest and latest login per user:


 

You may also like...