The resident list and the household cards at the village office, paired by no_kk by a real SQLite: INNER, LEFT, RIGHT, FULL, CROSS. See who has no partner and…
Why it matters
JOIN is the core of relational SQL: data is split over many tables precisely so it can be paired again. Picking the wrong JOIN, putting a condition in WHERE instead of ON, or forgetting the ON are the quietest data bugs: the result looks fine but silently loses or doubles rows.
The key idea
Every kind of JOIN differs in one thing only: the fate of a row with no partner
Common mistakes
LEFT JOIN acting like INNER, the NULL rows gone The right table’s condition went into WHERE after a LEFT JOIN. WHERE runs after the join and drops the rows whose right columns are NULL, so LEFT quietly becomes INNER. Put the condition in ON.
A row with a NULL column never joins, even against a NULLNULL = anything is NULL, not true, so a NULL key never matches in ON. A LEFT JOIN still keeps its row, the right columns NULL; to match NULL with NULL, SQLite has IS (w.no_kk IS k.no_kk).
Forgot the ON, the row count exploded Without ON a JOIN becomes a CROSS JOIN: every left row × every right row, 7 × 5 = 35 here, millions in production. SQLite and MySQL run it silently, PostgreSQL refuses. Always write the join condition.
Try it in this playground
Compare INNER with LEFT LEFT brings back the residents with no card, their card columns NULL; INNER drops them.
Find the NULL of a missing card A join that keeps a row with no partner fills its partner’s columns with NULL.
Remove the ON Every resident is paired with every card: 7 × 5 rows.
Move the card condition from WHERE into ON With LEFT JOIN, k.rt = 2 in ON keeps every resident; in WHERE it drops the NULL ones.