Junior — Middle
What is the purpose of the MIN function in SQL and how is it used to obtain the minimum value in data?
sobes.tech AI
Answer from AI
The MIN function in SQL is used to obtain the minimum value from a dataset for a specific column. It is used in aggregate queries to find the smallest value, such as the minimum price, date, or quantity.
Example of usage:
SELECT MIN(price) AS min_price FROM products;
This query will return the minimum value in the price column of the products table.
You can also use MIN with conditions or grouping:
SELECT category_id, MIN(price) AS min_price
FROM products
GROUP BY category_id;
Here, the minimum price for each category will be found.