Get the App
SLTechnology News&Howtos  ›  Database  › 

How to distinguish between MIN () and LEAST () in MySQL

Shulou Source: shulou.com Published: 2022-06-01 19:18:18 09月19日 Update

The following mainly brings you how to distinguish between MIN () and LEAST () in MySQL. I hope these contents can bring you practical use, which is also the main purpose of my editing MySQL how to distinguish MIN () and LEAST () this article. All right, don't talk too much nonsense, let's just read the following.

Grammar

The syntax for MIN () and LEAST () is:

MIN ([DISTINCT] expr) [over_clause] LEAST (value1,value2,...)

So the MIN () function accepts different keywords and OVER clauses (while the LEAST () function does not).

The main difference between the two functions is the parameters they accept.

Specifically:

1.MIN () receives a parameter

2.LEAST () receives multiple parameters

So MIN () is usually used to return the minimum value in the column in the database. A table can contain many rows, but this function returns the row with the lowest value.

LEAST (), on the other hand, returns the minimum parameter from the list of parameters passed to it. You can pass three arguments to this function and it will return the one with the lowest value.

Example 1-MIN () function

SELECT MIN (Population) AS 'Result'FROM City

Results:

+-+ | Result | +-+ | 42 | +-+

This example finds the city with the least population from the city table. The column containing the population of each city is called population.

The point of this example is that only one argument is provided to the function, but multiple rows are queried.

If you try to pass multiple arguments to the MIN () function, you will get an error.

Example 2-LEAST () function

SELECT LEAST (1,5,9) AS 'Result'

Results:

+-+ | Result | +-+ | 1 | +-+

In this case, we provide three parameters. Each parameter is compared to another parameter. This contrasts with the single argument provided to the MIN () function.

If you try to pass an argument to the LEAST () function, you will get an error.

Do you find it very helpful to tell the difference between MIN () and LEAST () in MySQL? If you need to know more, please continue to follow our industry information. I'm sure you'll like it.

Tags: Parameters functions minimum population content three below cities multiple results syntax errors differences two examples keywords specifically single on the other hand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Microsoft Huawei MySQL Linux