Smallest and largest with MIN and MAX
MIN and MAX find the smallest and largest value in a column:
SELECT MIN(list_price) AS cheapest, MAX(list_price) AS dearest
FROM productsThey work on dates (earliest and latest) and on text (first and last alphabetically) as well as on numbers.
Several aggregates at once
One query can return several summaries side by side, as long as every column is an aggregate:
SELECT COUNT(*) AS orders, MIN(order_date) AS first_order, MAX(order_date) AS latest_order
FROM ordersIf you mix an aggregate with a plain column, as in SELECT name, MAX(list_price) FROM products,
you get an error. Which name should it show? Tier 2 introduces GROUP BY, which solves this
properly.