SQL guides
One concept per page, a query you can run right there, the mistakes interviewers look for, and drills to lock it in.
- SQL JOINs explained: INNER, LEFT and anti-joinsA JOIN lines up rows from two tables using a condition, usually a foreign key matching a primary key. The type of join decides what happens to rows that have no match.
- SQL GROUP BY and HAVING: aggregate and filter groupsGROUP BY collapses rows that share a value into one row per group. Aggregates like COUNT, SUM, AVG, MIN and MAX then summarize each group.
- SQL window functions explained with examplesA window function computes a value across a set of related rows but, unlike GROUP BY, keeps every row. You get the detail and the summary side by side.
- RANK vs DENSE_RANK vs ROW_NUMBER in SQLAll three number rows in order. They only disagree about ties, and that's exactly what interview questions test.
- SQL LAG and LEAD: compare a row with the previous or next oneLAG(column) reads the value from the previous row in the window's order; LEAD reads the next one. They're how SQL compares a row with its neighbor.
- Running totals and moving averages in SQLSUM(x) OVER (ORDER BY day) adds up x from the first row to the current one: a running total. Window frames turn the same idea into moving averages.
- SQL CTEs (WITH clause) and recursive CTEsA common table expression (CTE) names a subquery with WITH so the main query can use it like a table. It's the cleanest way to break a hard question into steps.
- SQL CASE WHEN: conditional logic in queriesCASE WHEN is SQL's if/else. It returns a value per row based on conditions, so you can label rows, bucket numbers or build pivot columns.
- NULL in SQL: IS NULL, COALESCE and the mistakes NULL causesNULL means 'unknown'. Any comparison with it is unknown too, not true or false, so NULLs quietly drop out of filters unless you handle them on purpose.
- SQL date functions in PostgreSQL: date_trunc, intervals and date mathMost analytics questions are about time: per month, within 7 days, since signup. Postgres makes date math direct once you know a handful of functions.