Table of Contents
ToggleThe MIN() function returns the smallest value in a selected column, while the MAX() function returns the largest value.
Below is a selection from the Products table:
| ProductID | ProductName | SupplierID | CategoryID | Unit | Price (₹) |
|---|---|---|---|---|---|
| 1 | Basmati Rice | 1 | 1 | 1 kg packet | 85 |
| 2 | Toor Dal | 2 | 1 | 1 kg packet | 120 |
| 3 | Spices Mix | 3 | 2 | 500 g packet | 200 |
| 4 | Sunflower Oil | 4 | 3 | 1 litre bottle | 180 |
Find the lowest price in the Price column:
SELECT MIN(Price) AS SmallestPrice
FROM Products;
Find the highest price in the Price column:
SELECT MAX(Price) AS LargestPrice
FROM Products;
Return the smallest price for each category:
SELECT MIN(Price) AS SmallestPrice, CategoryID
FROM Products
GROUP BY CategoryID;
