×

sql · level 1 · unit 5 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

tells you how many rows there are.

So far every query has handed back rows. COUNT(*) is different: it counts the rows and hands back one number. Ask how many pets there are and you get 6.

COUNT is an : a function that squashes many rows into one answer. The * inside the brackets means count every row.

Add WHERE and it counts only the rows that pass, like how many pets are cats. Give the answer a name with AS to keep the top line tidy.

SELECT COUNT(*) AS pets FROM pets;

WHERE does its sieving before the counting starts, so only the rows that pass get counted.