MySQL · December 19, 2023

MySQL Command: MIN()

MySQL Command: MIN()

In the world of databases, MySQL is a popular choice for managing and organizing data efficiently. One of the essential commands in MySQL is MIN(), which allows users to find the minimum value in a specified column. In this article, we will explore the functionality and usage of the MIN() command in MySQL.

Understanding the MIN() Command

The MIN() command is used to retrieve the minimum value from a column in a MySQL database table. It is particularly useful when you need to find the smallest value in a specific column, such as the lowest price or the earliest date.

The syntax for using the MIN() command is as follows:

SELECT MIN(column_name) FROM table_name;

Here, column_name refers to the name of the column from which you want to find the minimum value, and table_name is the name of the table where the column resides.

Examples of Using MIN()

Let's consider a scenario where we have a table named "products" with the following structure:

+----+------------+-------+
| ID | Product    | Price |
+----+------------+-------+
| 1  | Laptop     | 1000  |
| 2  | Smartphone | 800   |
| 3  | Tablet     | 1200  |
+----+------------+-------+

To find the minimum price from the "products" table, we can use the MIN() command as follows:

SELECT MIN(Price) FROM products;

The result of this query will be:

<code++---------+
| MIN(Price) |
+-----------+
| 800       |
+-----------+

As you can see, the MIN() command returns the minimum value from the specified column, which in this case is the lowest price of any product in the table.

Using MIN() with Other Commands

The MIN() command can also be used in combination with other commands to retrieve more specific information. For example, you can use it with the WHERE clause to find the minimum value based on certain conditions.

Let's say we want to find the minimum price of products that belong to the "Laptop" category. We can modify our query as follows:

SELECT MIN(Price) FROM products WHERE Product = 'Laptop';

This query will return the minimum price of laptops from the "products" table.

Conclusion

The MIN() command in MySQL is a powerful tool for finding the minimum value in a specified column. Whether you need to find the lowest price, the earliest date, or any other minimum value, the MIN() command can help you retrieve the desired information efficiently.

For more information about VPS hosting solutions, visit Server.HK.