Join tables, group and choose, design safe databases and work with dates to build useful reports.
- 28 lessons
- 7 units
- 4 h 21 m in all
- £0, for good
what’s inside.
For people who finished Level 1, or can already write small programs with variables, decisions, loops and functions.
SQL Level 2 picks up where Level 1 ends. In 28 lessons you join tables, group and sieve results, nest queries, choose values with CASE, design linked tables with rules that keep bad data out, and count days between dates. It ends with a level check: one set of reports that works for five different libraries.
every lesson goes the same way.
- meet it
- guess first
- your turn
- fix it
- nailed it
unit 1
Groups and totals
Get one answer for every group, not one for the whole table.
- One answer per group8 minCount and total each kind of thing in a single query.
- Sorting and sieving groups9 minSieve the rows first, group them, then sort the answers.
- Picking groups with HAVING9 minKeep only the groups that pass a test.
- Groups inside groups9 minGroup by two columns at once for a finer report.
unit 2
Join tables together
Store each fact once, link tables by id, then bring them back together.
- Tables that point at each other9 minStore each fact once and link rows by their id.
- JOIN glues rows together10 minBring linked rows from two tables into one result.
- Short names for tables9 minGive tables aliases to keep joins short and clear.
- Join, then group10 minBuild a joined table, then sum it up per customer.
unit 3
More joins
Keep rows with no match, find what is missing and join three tables.
- LEFT JOIN keeps everyone9 minKeep every row from one table, matched or not.
- Finding what is missing9 minList the rows that have no match at all.
- Three tables at once10 minChain joins to answer questions that need three tables.
- Counting zeros10 minCount matches for every row, even the ones with none.
unit 4
Queries inside queries
Check values against lists, and use one query's answer inside another.
unit 5
Choose with CASE
Make a query choose a value for every row, and fill in the blanks.
unit 6
Rules that protect your data
Let the database refuse bad data before it ever gets in.
- No two the same8 minStop two rows sharing a value that must be one of a kind.
- A value when none is given8 minFill left-out columns with a sensible starting value.
- Checking values on the way in9 minWrite your own rule that every row must pass.
- Links that cannot break10 minMake the database refuse a foreign key that points nowhere.
unit 7
Design and dates
Link tables many to many, work with dates, then build a full report.
- Link tables10 minDesign a many-to-many link with a table in the middle.
- Dates are text in a set order10 minStore dates so they sort, compare and group correctly.
- Counting days10 minMove a date along and count the days between two dates.
- Putting it all together12 minTurn a librarian's brief into a working report.