MIN and MAX Functions in SQL

Level 3101 keystrokes

MIN and MAX find the smallest and largest values in a column.

SQL code

1SELECT
-- MIN returns the lowest price among the filtered rows
2 MIN(price) AS min_price,
-- MAX returns the highest price; together they give one result row
3 MAX(price) AS max_price
4FROM
5 products
-- WHERE runs before the aggregates, so only Electronics products count
6WHERE
7 category = 'Electronics';

Output

+-----------+-----------+
| min_price | max_price |
+-----------+-----------+
|     29.99 |    999.99 |
+-----------+-----------+
1 row in set
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this SQL code and how often they appear.

  • _× 2
  • '× 2
  • (× 2
  • )× 2
  • ,× 1
  • ;× 1
  • =× 1

More SQL examples at level 3

← SQL typing practice