The Min() function is used to fetch the minimum value in a set of values from the table. For example, when we want to find the least expensive product, the Min() function is the go-to function.
Syntax
SELECT MIN ( expression )
FROM table_name
[WHERE conditions];
Example
Here is the products table with a list of products and their price. Let us find out the least unit price and its product name.
select name as product_name, min(unit_price) as least_cost from sql_inventory.products;
So it selected the minuscule amount from the products table and its name.
Conclusion:
This is one way of effectively using the Min() function and can be paired up with the where, group by clauses.
- Log in to post comments