Difference between revisions of "MIN"
From SQLZOO
| Line 11: | Line 11: | ||
<h3>MIN</h3> | <h3>MIN</h3> | ||
<p>MIN finds the smallest values in a column or part of a column</p> | <p>MIN finds the smallest values in a column or part of a column</p> | ||
| − | <p>MIN | + | <p>MIN is an aggregate function it is normally used with GROUP BY. </p> |
<pre style='width:50ex'> | <pre style='width:50ex'> | ||
SELECT region, MIN(name) | SELECT region, MIN(name) | ||
| Line 22: | Line 22: | ||
The MIN column gives the "smallest" name in the region in the context of strings this is the first name alphabetically. | The MIN column gives the "smallest" name in the region in the context of strings this is the first name alphabetically. | ||
<source lang='sql' class='def'> | <source lang='sql' class='def'> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
SELECT region, MIN(name) | SELECT region, MIN(name) | ||
FROM bbc | FROM bbc | ||
| Line 37: | Line 31: | ||
<ul> | <ul> | ||
<li>[[AVG function]]</li> | <li>[[AVG function]]</li> | ||
| − | <li>[ | + | <li>[http://sqlzoo.net/w/index.php/SUM SUM function]</li> |
<li>[http://sqlzoo.net/w/index.php/MAX MAX function]</li> | <li>[http://sqlzoo.net/w/index.php/MAX MAX function]</li> | ||
</ul> | </ul> | ||
Revision as of 08:53, 13 July 2012
| MIN(f) | ||
|---|---|---|
| Engine | OK | Alternative |
| ingres | Yes | |
| mysql | Yes | |
| oracle | Yes | |
| postgres | Yes | |
| sqlserver | Yes | |
MIN
MIN finds the smallest values in a column or part of a column
MIN is an aggregate function it is normally used with GROUP BY.
SELECT region, MIN(name)
FROM bbc
GROUP BY region
With a GROUP BY region statement each region shows up just once.
The MIN column gives the "smallest" name in the region in the context of strings this is the first name alphabetically.
SELECT region, MIN(name) FROM bbc GROUP BY region
See also