Play n Tools

Free tools & games for everyone

Free · No sign-up · No accounts

SQL joins & schema lab

See what every SQL join returns on tables you can edit, with the SQL to copy; try GROUP BY; and check a table design for keys and normal forms.

How to use

  1. Joins: edit the two small tables (comma-separated, first line = column names; write NULL or leave a cell empty for a missing value). Pick a join and the columns to match.
  2. The result, a picture of which rows it keeps, and the SQL to copy all update as you type.
  3. Group by: pick a table, the column to group on and what to work out for each group.
  4. Keys & normal forms: list the columns and the dependencies you know ("course decides teacher" is course -> teacher), then press Check the design.

Keyboard and touch

Arrow keys on the tabsChange part of the lab
Typing in a tableUpdates the join result at once

Tips

  • NULL never equals anything, not even another NULL, so rows with a missing key never match in a join.
  • A key that appears twice in one table makes extra result rows: two orders for one customer give two joined rows.
  • RIGHT JOIN is LEFT JOIN with the tables swapped; many people only use LEFT JOIN for that reason.
  • COUNT(*) counts rows; COUNT(column) skips NULLs. SUM and AVG skip NULLs too.
  • A table is in BCNF when every dependency's left side is a key. Splitting to BCNF never loses rows, but a dependency can end up spread over two tables.

About this lab

The joins follow standard SQL rules, including three-valued logic for NULL keys; the semi and anti joins are shown with the EXISTS and LEFT JOIN … IS NULL patterns that most databases accept. The design checker uses attribute closures over your dependencies to find every candidate key (checking each set of columns from the smallest up), then tests each dependency for 2NF (no part of a key decides a non-key column), 3NF and BCNF, and splits the table with the standard BCNF decomposition. It is a teaching tool for small designs (up to 16 columns), not a database. Nothing is sent anywhere.

See you tomorrow!

A fresh daily puzzle every morning, and new tools added every month.

Browse every product