SQL
// topic

SQL Fundamentals

SELECTs, joins, group-bys, subqueries, CTEs. The core vocabulary.

// sql fundamentals

Self-joins without the headache: a sql self join example that sticks

A self-join is a normal join where a table is compared against itself. It looks scary until you give the two copies different names, then it's just a join like any other.

25 Jul 20267 min
// sql fundamentals

Subqueries vs CTEs: a query inside a query, made readable

Both let you use the result of one query inside another. A CTE just gives that inner query a name up front, so the whole thing reads top to bottom instead of inside-out.

12 Jul 20267 min
// sql fundamentals

String & date functions: cleaning and slicing the messy columns

Real data is full of messy text and dates. A handful of built-in functions (LOWER, TRIM, DATE_TRUNC, EXTRACT) cover most of what an analyst does day to day.

12 Jul 20267 min
// sql fundamentals

Aggregate functions: COUNT, SUM, AVG and their sharp edges

The functions that turn many rows into one number look simple, but COUNT(*) vs COUNT(column), and how they treat blanks, is a favourite beginner interview question.

12 Jul 20266 min
// sql fundamentals

Data types & casting: why '10' + 5 sometimes breaks

Every column has a type: text, number, date, true/false. Knowing the type matters because a number stored as text won't add up, and comparing across types causes subtle bugs.

12 Jul 20266 min
// sql fundamentals

NULL handling: what 'blank' really means in SQL

NULL isn't zero and isn't an empty string, it means 'unknown.' And comparing anything to 'unknown' gives you 'unknown,' which quietly drops rows you expected to keep.

12 Jul 20267 min
// sql fundamentals

DISTINCT, LIMIT, aliases & ordering: the small everyday tools

Four little tools you'll use in almost every query: remove duplicates, cap the rows, rename columns, and sort by more than one thing.

12 Jul 20265 min
// sql fundamentals

UNION, INTERSECT, EXCEPT: stacking query results on top of each other

A JOIN adds columns side by side. These stack the rows of two queries into one list: combine them, keep only the overlap, or subtract one from the other.

12 Jul 20266 min
// sql fundamentals

The five JOIN types: sticking two tables together

A JOIN glues two tables side by side where a shared column matches. The five types just differ on what happens to rows that don't find a match.

12 Jul 20268 min
// sql fundamentals

GROUP BY & HAVING: turning many rows into one summary row

GROUP BY rolls many rows up into one summary per group. HAVING filters those summaries. The classic beginner mix-up is using WHERE where you needed HAVING.

12 Jul 20266 min
// sql fundamentals

SELECT, WHERE, ORDER BY: the three words in almost every query

Every SQL query you'll write starts with picking columns, filtering rows, and sorting the result. Get comfortable with these three and you can read most queries.

12 Jul 20265 min