Learn with Abdou

Chapter 10 · Concept 3 of 5 · Practice

The orphan hunt loses the orphan

LEFT JOIN from staging to the parent, exclusion as a decision · level 1 of 6

Opening your saved work…

Sign in to save across devices → · Download your guest work before switching accounts.

The orphan hunt loses the orphan · LEFT JOIN from staging to the parent, exclusion as a decision · level 1 of 6

Every staged row beside its parent

Level 1: Watch it answered · Exercise 1 of 1

Show every staged row beside the gear type it names: serial, type_id and the gear type's name for all six rows in file order, keeping the rows that find no parent.

Data: Trail Gear: build rehearsal.

Why it works, clause by clause

  1. FROM stg_items s: start from the child side, the rows that need a parent.
  2. LEFT JOIN gear_types g ON g.id = CAST(s.type_id AS INTEGER): the staged ids are text, so the ON converts them, and every staged row stays, matched or not.
  3. TG-103 comes back with NULL in gear_type. That NULL is the orphan, and it is the evidence behind load_audit's Unknown gear type.

From the reading: Keep the row that has no parent, paragraph 3

The queryOpening the database…
SELECT s.serial, s.type_id, g.name AS gear_type
FROM stg_items s
LEFT JOIN gear_types g ON g.id = CAST(s.type_id AS INTEGER)
ORDER BY s.rowid;
Open in the playground

Query results

Run it to see the result here.

Run it to see the result here.

Practice here is evidence for you and your instructor, never a grade. Grades live in Canvas.