Databases
SQL: joins, grouping and constraints
What each join returns, how GROUP BY and HAVING differ, and how NULL behaves.
In two minutes
One idea to a line
INNER JOIN keeps matching rows only. LEFT JOIN keeps every left row and fills NULL where nothing matches. FULL JOIN keeps both sides.
WHERE filters rows before grouping; HAVING filters groups after aggregation. Aggregates (COUNT, SUM) cannot appear in WHERE.
NULL is not equal to anything, not even NULL. Test it with IS NULL. COUNT(*) counts rows; COUNT(col) skips NULLs.
UNION removes duplicates, UNION ALL keeps them and is faster.
PRIMARY KEY is unique and not null; UNIQUE allows NULL (in most systems); a CHECK constraint restricts values; ON DELETE CASCADE removes dependent rows.
Slips people make here
Interviewers know them too
Writing `= NULL` instead of `IS NULL`.
Putting an aggregate in WHERE.
Expecting COUNT(column) to count NULL values.
Your practice here
Not started
10 written questions, and 1 kind of calculation that change every time
No answers yet