SQL Interview: Joins, Keys and Constraints
The questions asked in almost every SQL interview, with short answers you can actually say out loud and the follow up the interviewer will ask next.
Combining rows from several tables.
10 notes tagged
The questions asked in almost every SQL interview, with short answers you can actually say out loud and the follow up the interviewer will ask next.
Fifteen exercises combining joins, grouping and having, each with the solution and a note on the trap it was designed to expose.
What the engine actually does: full scans versus index seeks, nested loop and hash joins, and why a sort or a temporary table appears in your plan.
Two tables that both have many of each other need a third table. Learn the junction table pattern, its key design, and how to query and count across i...
The same question answered four ways, with a straight comparison of readability, NULL safety and cost - and a rule for choosing between them.
Why a join multiplies rows, how to detect it, and the anti join patterns that answer "which rows have no match at all".
Building queries across four or more tables: reading a join chain, non equality conditions, join order, and keeping a long query readable.
The three joins people meet last: keeping unmatched rows from both sides, deliberate Cartesian products, and joining a table to itself.
Outer joins keep unmatched rows and fill the missing side with NULL. Learn LEFT and RIGHT JOIN, and the one mistake that silently turns an outer join...
INNER JOIN keeps only rows that match on both sides. Learn the syntax, how the join condition works, and why unmatched rows silently disappear.