Tell lrnit what you want to master.

Chapters of lessons that start from what you already know.

What a lesson looks like

From the course SQL Inner Join Fundamentals

Writing Your First INNER JOIN on Primary and Foreign Keys

An INNER JOIN pairs each order with the customer whose primary key equals its foreign key, and silently discards every row that finds no partner

A monthly report that joins orders to customers and comes out short has usually lost rows at the join, not in the data. An INNER JOIN keeps only rows that match on both sides, so any row without a partner vanishes with no error and no warning. Holding your own here takes three abilities, in this order: writing the join on the right key pair, predicting by hand which rows will vanish, and checking row counts against the source tables to prove nothing disappeared unexpectedly. The key pair comes first because every later check depends on it.

The key pair is a primary key (the column that uniquely identifies each row, here customers.customer_id) and a foreign key (a column in another table that stores those identifiers, here orders.customer_id). The ON clause states the matching rule. For every possible pairing of one customer row and one order row, the database keeps the pair only when the ON condition is true.

The bookstore has these rows:

sql
INSERT INTO customers VALUES (1,'Amara Okafor','Lagos'),(2,'Ben Carter','Leeds'),(3,'Chloe Martin','Lyon'),(4,'Dev Patel','Pune');
INSERT INTO orders VALUES (101,1,'Dune',12.50),(102,1,'Emma',8.00),(103,2,'Ulysses',15.75),(104,3,'Beloved',11.20),(105,NULL,'Walden',9.40);

Traced by hand: orders 101 and 102 carry customer_id 1, so both pair with Amara. Order 103 pairs with Ben, 104 with Chloe. Order 105 carries NULL, which means "no value", and NULL equals nothing, not even another NULL, so it pairs with no one.

sql
SELECT c.name, o.order_id, o.book_title, o.total
FROM customers c
INNER JOIN orders o ON c.customer_id = o.customer_id
ORDER BY o.order_id;

The letters c and o are aliases, short names for the tables so that c.customer_id and o.customer_id can be told apart.

text
name | order_id | book_title | total
Amara Okafor | 101 | Dune | 12.5
Amara Okafor | 102 | Emma | 8.0
Ben Carter | 103 | Ulysses | 15.75
Chloe Martin | 104 | Beloved | 11.2

Counting rows on each side proves what was lost:

sql
SELECT
  (SELECT COUNT(*) FROM customers) AS customers_rows,
  (SELECT COUNT(*) FROM orders) AS orders_rows,
  (SELECT COUNT(*) FROM orders o INNER JOIN customers c ON c.customer_id = o.customer_id) AS joined_rows;
text
customers_rows | orders_rows | joined_rows
4 | 5 | 4

Five orders went in and four came out. The missing one is Walden, 9.40, so a sales total taken from this join is short by exactly that amount. Rows drop from the customers side too, whenever a customer has no matching order.

The INNER JOIN pairs orders with customers on matching customer IDs. Order 105 (Walden) is excluded because its customer_id is NULL. Customer Dev Patel is excluded because no order references his customer_id.

Look at the four result rows and the four customers inserted. Which customer's name appears in customers but in no row of the join result? Type the name.

The database does not apply the declared foreign key to the join. It evaluates whatever ON says, and nothing else. Rewrite the condition as ON c.customer_id = o.order_id - 100 and the query runs without complaint, returning Dev Patel paired with order 104, a Beloved purchase that Chloe made. The foreign key constraint guards inserts, so bad orders cannot be stored. It does not rescue a join whose ON compares the wrong columns, and the wrong result looks just as tidy as the right one. Match primary key to foreign key every time, then check the counts.

Write your goal

What the studies found

  1. Retrieval improved learning in the studies.

    In the studies reviewed, retrieving an idea from memory produced more learning than studying it again.

    The studies

    Across 222 classroom studies involving 48,478 students, retrieving an idea from memory improved learning compared with studying it again. These studies cover many test formats, but they do not show that every short answer is judged accurately.

  2. Spaced study improved later recall.

    For learners like the ones studied, spacing study sessions helped knowledge last.

    The studies

    In an online study of 1,354 adults, spaced study kept material available longer, with the useful gap changing with how long it needed to last. These studies do not validate lrnit's schedule or show that one interval fits every subject.

  3. Self-explanation prompts improved learning.

    In the studies reviewed, generating an explanation supported learning; in an online course, doing activities was associated with stronger learning than watching or reading.

    The studies

    Across studies of prompted self-explanation and observational data from a psychology course online, producing an explanation or doing the work was linked to stronger learning than passive study. These studies do not show that runnable code caused the gain, or that explaining always beats equal-time rereading.

  4. Pre-training improved transfer in the experiments.

    For learners like the ones studied, learning the parts before a mechanism ran supported later performance.

    The studies

    In three experiments, learners who saw the parts and their states before a mechanism ran performed better on later transfer tasks. Goal-setting research also supports specific, demanding goals, but neither source tests lrnit's exact briefing.

  5. Unrestricted AI help lowered unaided performance.

    For students in the study, unrestricted AI help raised practice scores but lowered unaided performance.

    The studies

    In a field trial with about a thousand high-school maths students in Turkey, unrestricted AI help raised practice scores but lowered later unaided exam results. The study does not test lrnit's exact question-only approach or show the same result in other subjects.