SQL
111 highly-curated topics available for revision.
1. Fundamentals
SQL Basics
HighThe foundation of Relational Databases.
DDL, DML, DCL, TCL
MediumThe four categories of SQL commands.
Primary Key
HighThe unique identifier for a row.
Foreign Key
HighCreating relationships between tables.
Constraints
HighRules that prevent garbage data from entering your database.
NULL Values
HighThe billion-dollar mistake in database design.
Data Types
MediumChoosing the exact memory footprint for your data.
Aggregate Functions
HighSummarizing massive amounts of data.
2. Queries
SELECT
HighRetrieving data from the database.
WHERE
HighFiltering rows based on conditions.
GROUP BY
HighSmashing rows together based on common values.
HAVING
MediumThe WHERE clause for aggregated data.
ORDER BY
MediumSorting your results.
DISTINCT
MediumRemoving duplicate rows from your results.
LIMIT & OFFSET
MediumFetching data in chunks.
CASE
MediumIf/Else logic directly inside the database.
Subqueries
HighQueries inside of queries.
Correlated Subqueries
HighThe performance killer of SQL.
Common Table Expressions (CTEs)
HighMaking complex SQL readable.
Recursive CTEs
MediumNavigating trees and hierarchies in SQL.
3. Joins
SQL Joins
HighCombining data across multiple tables.
INNER JOIN
HighThe strict intersection.
LEFT JOIN
HighKeep everything on the left, even if there's no match.
RIGHT JOIN
The mirrored opposite of a Left Join.
FULL OUTER JOIN
Return everything from everywhere.
CROSS JOIN
MediumThe Cartesian Product.
Self Join
MediumWhen a table joins with itself.
4. Indexes
Database Indexes
HighHow databases find data instantly.
The B-Tree Index
HighThe mathematical engine behind SQL.
Clustered vs Non-Clustered Indexes
HighHow data is physically stored on the hard drive.
Composite Index
HighIndexing multiple columns simultaneously.
Covering Index
HighThe holy grail of SQL query optimization.
Unique Index
MediumEnforcing absolute data integrity at the storage layer.
Partial Index
MediumIndexing only the data you care about.
Index Selectivity
HighWhy the database sometimes ignores your index.
Index Cardinality
MediumThe uniqueness of your data.
When NOT to use Indexes
HighThe hidden costs of over-indexing.
5. Transactions
ACID Properties
HighThe mathematical guarantee that your database won't lose money.
Transactions
HighGrouping queries into atomic units of work.
Isolation Levels
HighBalancing data accuracy with concurrency.
Dirty Read
MediumReading data that never existed.
Non-Repeatable Read
MediumWhen the ground shifts beneath your feet.
Phantom Read
MediumWhen the database summons ghosts.
Serialization Anomaly
When perfect snapshots aren't enough.
Pessimistic Locking
HighAssuming the worst and locking the door.
Optimistic Locking
HighAssuming everything will be fine, and failing gracefully if it isn't.
6. Database Design
Normalization
HighThe mathematical process of eliminating data duplication.
First Normal Form (1NF)
MediumThe rule of atomic values.
Second Normal Form (2NF)
MediumEliminating partial dependencies.
Third Normal Form (3NF)
HighEliminating transitive dependencies.
Denormalization
HighIntentionally breaking the rules for performance.
One-to-One (1:1)
Splitting a single entity across two tables.
One-to-Many (1:N)
HighThe foundation of relational databases.
Many-to-Many (M:N)
HighResolving complex relationships with Junction Tables.
Polymorphic Associations
When a foreign key points to multiple tables.
7. Performance
Query Execution Plan
HighHow the database actually runs your code.
Table Scans (Seq Scan)
HighReading the entire book to find one word.
The N+1 Problem
HighThe most common ORM performance killer.
Connection Pooling
HighWhy serverless functions crush your database.
Materialized Views
MediumCaching complex queries as physical tables.
Query Caching
HighWhy the fastest query is the one you never run.
Prepared Statements
HighOptimizing execution and stopping hackers.
SQL Injection (SQLi)
HighThe most famous vulnerability in computer history.
Database Vacuuming
MediumWhy PostgreSQL requires a garbage collector.
Table Partitioning
MediumSplitting massive tables into smaller chunks.
8. Concurrency
Database Locks
HighHow databases prevent chaos during concurrent access.
Deadlocks
HighThe Mexican Standoff of databases.
MVCC (Multi-Version Concurrency Control)
HighWhy readers never block writers.
Write-Ahead Log (WAL)
HighHow databases survive power failures.
Read/Write Locks
MediumThe mechanics of Shared vs Exclusive access.
Row-Level Locks
MediumPrecision locking for high concurrency.
Table-Level Locks
MediumThe nuclear option of database concurrency.
9. Advanced SQL
Window Functions
HighPerforming math across rows without squashing them.
ROW_NUMBER, RANK, DENSE_RANK
HighThe top N per group problem.
LEAD and LAG
MediumTime travel across rows.
Views
MediumVirtual tables for security and simplicity.
Triggers
MediumEvent listeners inside the database.
Stored Procedures
MediumWriting full programs inside the database.
User-Defined Functions (UDFs)
Writing your own SQL keywords.
JSON in SQL
HighBlurring the line between SQL and NoSQL.
Full-Text Search
MediumBuilding a search engine without Elasticsearch.
UPSERT (Insert or Update)
HighHandling conflicts elegantly.
10. Database Scaling
Vertical Scaling (Scaling Up)
HighThrowing money at the problem.
Horizontal Scaling (Scaling Out)
HighDividing and conquering the traffic.
Read Replicas (Primary-Replica)
HighScaling read-heavy applications.
Database Sharding
HighScaling write-heavy applications.
Sharding Strategies
MediumHow to physically divide the data.
Consistent Hashing
HighHow to add a server without breaking everything.
11. SQL vs NoSQL
Relational vs Non-Relational
HighThe great database war of the 2010s.
Document Databases
HighStoring JSON directly on the hard drive.
Key-Value Stores
HighThe ultimate caching layer.
Graph Databases
When the relationships are more important than the data.
Wide-Column Stores
MediumWriting data at the speed of light.
12. Practical Queries
Find Duplicates
HighIdentifying dirty data.
Delete Duplicates
HighSurgically removing clones.
Nth Highest Value (Second Highest Salary)
HighThe most famous SQL interview question.
Cumulative Sum (Running Total)
HighAdding it up as we go.
Moving Average
MediumSmoothing out the spikes.
Year-Over-Year (YoY) Growth
MediumComparing the present to the past.
Retention Analysis (Cohorts)
HighFiguring out who comes back.
Handling NULLs (COALESCE)
HighAvoiding the Three-Valued Logic trap.
Dates and Timezones
HighThe hardest part of software engineering.
Hierarchical Data (Trees)
MediumWho manages the manager's manager?
Pivoting Data
MediumTurning rows into columns.
Histograms and Binning
MediumGrouping continuous numbers into discrete buckets.
13. Interview Questions
Top N Per Group
HighThe classic window function test.
Active Users in Rolling Window
MediumThe 30-Day Active User metric.
Gaps and Islands
HighFinding sequential groupings.
Employee Manager Salary
HighThe classic Self-Join test.
Consecutive Numbers
MediumFinding three-in-a-row.
Department Highest Salary
MediumThe multi-column join challenge.