Changing and summarising data

Changing and deleting rows safely, and turning many rows into counts, totals and averages, per group.

About 5 hours of study

Learning objectives

Lessons

  1. 1

    Changing and deleting rows

    UPDATE changes values and DELETE removes rows, both only where the WHERE condition holds. Without WHERE they touch every row.

  2. 2

    Counting and totals: GROUP BY and HAVING

    COUNT, SUM, AVG, MIN and MAX sum up many rows; GROUP BY gives one result row per group; HAVING keeps only some groups.

Module practice

Module quiz

1. What does UPDATE products SET price = 0; do?
2. Which function counts the rows of a table?
3. A DELETE has a WHERE that matches no row. What happens?
4. A table has 8 rows, and 3 have NULL in email. What is COUNT(email)?
5. Where does a condition on COUNT(*) go?
6. SELECT dept, COUNT(*) FROM staff GROUP BY dept. How many rows come back?
7. In SQLite, what is 7 / 2?

‹ Tables and basic queriesKeys and joins ›