MIN()The MIN() aggregate function returns the smallest value from a set of values. It's commonly used with numeric, date/time, or string columns (string comparison follows collation rules).
MIN() ignores NULLs; if all values are NULL, result is NULL.GROUP BY to compute minima per group.
-- Create a sample products table
CREATE TABLE Products (
ProductID INT PRIMARY KEY,
Category VARCHAR(50),
Price DECIMAL(8,2),
AddedOn DATE
);
-- Insert sample rows
INSERT INTO Products (ProductID, Category, Price, AddedOn) VALUES
(1, 'Books', 199.99, '2024-01-12'),
(2, 'Books', 149.50, '2024-03-05'),
(3, 'Gadgets', 499.00, '2024-02-20'),
(4, 'Gadgets', NULL, '2024-05-01'),
(5, 'Books', 99.99, '2024-06-10');
-- 1) Minimum price overall
SELECT MIN(Price) AS MinPrice FROM Products;
-- 2) Minimum price per category (grouped)
SELECT Category, MIN(Price) AS MinPrice
FROM Products
GROUP BY Category;
-- 3) Conditional minimum using COALESCE
SELECT MIN(COALESCE(Price, 999999)) AS MinPriceIgnoringNulls FROM Products;
Result: 99.99 — lowest non-NULL price.
MIN() ignores NULL values.