Cover Image for MySQL min()
82 views

MySQL min()

The MIN() function in MySQL is an aggregate function used to retrieve the minimum (smallest) value from a specified column. It is commonly used to find the minimum value in a dataset or to retrieve the earliest date in a date column. The basic syntax of the MIN() function is as follows:

MIN(expression)
  • expression: This should be a column or an expression from which you want to find the minimum value.

Here are some common ways to use the MIN() function:

  1. Find the Minimum Value in a Column:
    To find the minimum value in a column, use MIN(column_name).
   SELECT MIN(price) FROM products;
  1. Find the Minimum Date in a Date Column:
    To find the earliest date in a date column, use MIN(date_column).
   SELECT MIN(order_date) FROM orders;
  1. Find the Minimum Value Based on a Condition:
    You can find the minimum value in a column that meets specific conditions by using the MIN() function with a WHERE clause.
   SELECT MIN(score) FROM test_scores WHERE subject = 'Math';
  1. Find the Minimum Value Grouped by a Column:
    When you want to find the minimum value for each group within a dataset, you can use the GROUP BY clause with the MIN() function.
   SELECT department, MIN(salary) FROM employees GROUP BY department;

The MIN() function returns the smallest value from the specified column. It’s a helpful tool for identifying the minimum value in your data, whether that’s the lowest price, the earliest date, or the minimum score in a specific category.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS