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
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
- FROM stg_items s: start from the child side, the rows that need a parent.
- 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.
- 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
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;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.