Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report