SQL MIN() and MAX() Functions
The
SQL MIN() and MAX()
Functions
The MIN() function returns the smallest value of
the selected column.
The MAX() function returns the largest value of
the selected column.
MIN function: The MIN function returns
the smallest value in a column or a set of values.
Syntax:
SELECT MIN(column_name)
FROM table_name
WHERE condition;
Example:
Suppose you have a "sales"
table with a "price" column, and you want to find the minimum price
in the table. You can use the following query:
SELECT MIN(price) FROM
sales;
This will return the smallest value in
the "price" column of the "sales" table.
MAX function: The MAX function returns the largest value in a column or a set of values.
Syntax:
SELECT MAX(column_name)
FROM table_name
WHERE
condition;
Example:
Suppose you have a "sales"
table with a "price" column, and you want to find the maximum price
in the table. You can use the following query:
SELECT MAX(price) FROM
sales;
This will return the largest value in
the "price" column of the "sales" table.
Note: The MIN and MAX functions can also be used with other aggregate functions and in combination with other SQL clauses like WHERE, GROUP BY, and HAVING to perform more complex queries.
0 Comments