The Sqlism Blog

SQL, explained clearly

Tutorials, performance tips, interview guides, and database deep-dives — written to make SQL click.

Practical Tutorials Performance Tips Interview Guides
Fundamentals

SQL Execution Order Explained (Why WHERE Runs Before SELECT)

SQL doesn't run in the order you write it. The real logical order — and why you can't filter on a SELECT alias.

Jul 20, 20267 min read Read
Fundamentals

SELECT vs WHERE vs HAVING – Real Examples

Row filter, group filter, or projection? What each clause really does — with real, side-by-side SQL.

Jul 20, 20266 min read Read
Joins

INNER JOIN vs LEFT JOIN vs RIGHT JOIN (With Visuals)

Venn diagrams, sample tables, and the exact rows each join returns — plus the classic LEFT-JOIN gotcha.

Jul 20, 20268 min read Read
Aggregation

GROUP BY Mistakes That Break SQL Queries

Seven GROUP BY traps — from non-grouped columns to join fan-out — each with a clear fix and example.

Jul 20, 20267 min read Read
Aggregation

COUNT(*) vs COUNT(column) – The Difference Nobody Explains

One counts rows, one skips NULLs, one counts unique values — proven on a single dataset. Plus the COUNT(1) myth.

Jul 20, 20266 min read Read
NULL Handling

NULL Handling in SQL (IS NULL vs = NULL)

Why = NULL never works, three-valued logic, the NOT IN trap, and COALESCE — with fixes.

Jul 20, 20267 min read Read
Fundamentals

ORDER BY Before or After GROUP BY?

Short answer: after — always. Why, plus exactly what you can sort by once you've grouped.

Jul 20, 20265 min read Read
Debugging

Why SQL Queries Return Unexpected Results

A 60-second debugging checklist: NULL logic, join fan-out, integer division, precedence, and more.

Jul 20, 20268 min read Read
Window Functions

Window Functions Explained Like You're 10

OVER(), PARTITION BY, and running totals — window functions demystified with the simplest possible examples, no jargon required.

Jul 20, 20268 min read Read
Window Functions

ROW_NUMBER vs RANK vs DENSE_RANK

Three ranking functions that look similar and behave very differently with ties. Which one to reach for, with side-by-side output.

Jul 20, 20266 min read Read
CTEs & Subqueries

CTEs vs Subqueries – When to Use What

Same job, different tools. When a CTE makes a query more readable — and when a subquery is actually the better call.

Jul 20, 20267 min read Read
CTEs & Subqueries

Correlated Subqueries Explained Simply

The subquery that references its outer query, row by row. How they work, why they're slow, and when they're worth it.

Jul 20, 20266 min read Read
CTEs & Subqueries

SQL Recursive CTEs With Examples

Walking a hierarchy — org charts, category trees, and bill-of-materials — with WITH RECURSIVE, explained from the ground up.

Jul 20, 20268 min read Read
Aggregation

Advanced GROUP BY Techniques You Should Know

ROLLUP, CUBE, GROUPING SETS, and conditional aggregation — GROUP BY tricks that go well beyond the basics.

Jul 20, 20267 min read Read
Performance

How SQL Optimizers Actually Work

What actually happens between your query and its results: statistics, execution plans, and why two "equivalent" queries can run at very different speeds.

Jul 20, 20269 min read Read
Performance

Why SQL Queries Are Slow (And How to Fix Them)

Six root causes behind almost every slow query — missing indexes, bad predicates, SELECT *, and more — with before/after timing.

Jul 23, 202610 min read Read
Performance

Indexes Explained With Real Examples

B-trees, single-column, composite, and covering indexes — how each one actually works, with real query timing.

Jul 23, 20269 min read Read
Performance

Index Scan vs Table Scan

What each scan type does physically, and the selectivity math that decides which one the optimizer picks.

Jul 23, 20268 min read Read
Performance

When NOT to Use Indexes

Five situations where adding an index makes performance worse, not better — with real INSERT timing before and after.

Jul 23, 20268 min read Read
Performance

EXPLAIN Query Plan – Beginner to Advanced

From your first EXPLAIN ANALYZE to cost numbers, join algorithms, and spotting a bad row estimate.

Jul 23, 202611 min read Read
Performance

SQL Optimization Checklist

Diagnose, rewrite, index, verify, monitor — the exact order that actually works, with a full before/after example.

Jul 23, 20269 min read Read
Performance

Top SQL Performance Anti-Patterns

Seven mistakes that pass code review but quietly wreck performance — each with a fix and before/after timing.

Jul 23, 202610 min read Read
Aggregation

Why HAVING Is Used After GROUP BY

You can't filter on a total that doesn't exist yet — the logical reason HAVING comes after GROUP BY, and how it differs from WHERE.

Jul 26, 20267 min read Read
Aggregation

SQL GROUP BY Without Aggregate Function

GROUP BY doesn't need COUNT() or SUM() — at its core it's a deduplication tool. How it compares to DISTINCT.

Jul 26, 20267 min read Read
Fundamentals

SQL Alias Scope Explained

Why WHERE can't see a SELECT alias but ORDER BY can — and how GROUP BY, HAVING, and table aliases scope differently.

Jul 26, 20268 min read Read
Interview

SQL Tricky Interview Questions With Answers

Eight classic traps — NULL comparisons, second-highest salary, UNION vs UNION ALL — with wrong vs correct output tables.

Jul 27, 202611 min read Read
Interview

SQL Output Based Interview Questions

Given this table and this query — what comes out? Six predict-the-output questions with wrong vs correct results.

Jul 27, 202610 min read Read
Interview

SQL Joins Interview Questions With Answers

Cartesian products, self-joins, and join fan-out — six join questions with wrong vs correct output tables.

Jul 27, 202610 min read Read
Interview

SQL CASE Statement Interview Questions

Simple vs searched CASE, pivoting with conditional aggregation, and the missing-ELSE trap — with output tables.

Jul 27, 20269 min read Read
Interview

SQL Window Function Interview Questions

ROW_NUMBER vs RANK vs DENSE_RANK with ties, running totals, and LAG/LEAD — with output tables.

Jul 27, 202610 min read Read
Interview

SQL GROUP BY Interview Questions

The ungrouped column error, WHERE vs HAVING order, and finding duplicates — with wrong vs correct output tables.

Jul 27, 20269 min read Read
Interview

SQL Subquery Interview Questions

Correlated vs non-correlated, IN vs EXISTS, and the NOT IN with NULL trap — with output tables.

Jul 27, 202610 min read Read
Interview

SQL Mistakes in Interviews

It's rarely the syntax — join fan-out, NULL assumptions, and not narrating your reasoning out loud.

Jul 27, 202611 min read Read

New articles are on the way.

Get new SQL articles in your inbox

One email when we publish something new. No spam, no fluff — just SQL that clicks.

We'll send a one-time confirmation email — no spam, unsubscribe with one click, any time.