Skip to main content

SQL

Why does SQL exist?

Imagine you work at a store and your boss asks: "How much did each product category earn last month?"

Your data is in a spreadsheet. If you have a hundred rows, you can filter and scroll through it. But most real businesses have millions of rows — too many to scan by hand, too big for Excel to even open.

A database is a system built to hold that much data and search it fast. SQL is the language you use to ask it questions.

You write something like:

SELECT category, SUM(revenue)
FROM sales
WHERE month = 'January'
GROUP BY category

And in under a second, the database hands you exactly the answer. No scrolling. No pivot tables. No "my Excel crashed."

Almost all company data lives in a database. Sales records, user events, financial transactions, inventory — it is all there. SQL is the only language databases speak, which is why it is the first thing every data analyst learns.

What You'll Learn

  • Writing queries to retrieve and filter data
  • Aggregating and grouping records
  • Joining multiple tables together
  • Using subqueries and CTEs for readable, modular SQL
  • Window functions for running totals, rankings, and comparisons

Lessons

Getting Started

LessonConcept
Introduction to SQLWhat SQL is, how databases work, and your first queries

Your First Query

LessonConcept
SELECTRetrieve columns from a table
FROMSpecify the source table and use aliases
WHEREFilter rows by a condition
AND / ORCombine multiple filter conditions

Filtering Techniques

LessonConcept
INMatch against a list of values
BETWEENFilter by an inclusive range
LIKEPattern matching on strings
IS NULL / IS NOT NULLCheck for missing values

Shaping Results

LessonConcept
ASAlias columns and tables for readability
DISTINCTRemove duplicate rows
ORDER BYSort the result set
LIMIT / TOPRestrict the number of rows returned

Joining Tables

LessonConcept
JOINCombine matching rows from two tables
ONDefine the join condition
LEFT JOINKeep all left-side rows, NULL-fill the right

Aggregating Data

LessonConcept
Aggregate FunctionsCOUNT, SUM, AVG, MIN, MAX
GROUP BYGroup rows for aggregation
HAVINGFilter groups after aggregation

How SQL Thinks

LessonConcept
SQL Execution OrderThe order SQL actually processes your query

Writing Cleaner Queries

LessonConcept
CASE WHENConditional logic in queries
WITH (CTEs)Named temporary result sets

Window Functions

LessonConcept
Window FunctionsOVER, PARTITION BY - compute across rows without collapsing them
ROW_NUMBER / RANK / DENSE_RANKRanking rows within a partition
LAG / LEADAccess values from adjacent rows
Running Totals & Moving AveragesCumulative sums, sliding windows, and frame specs

Set Operations & Subqueries

LessonConcept
SubqueriesScalar, table, and correlated subqueries
UNION / INTERSECT / EXCEPTCombine result sets vertically
EXISTS / NOT EXISTSTest for row presence safely

Useful Functions

LessonConcept
COALESCE / NULLIFHandle NULLs gracefully
Date & Time FunctionsTruncate, extract, and compute with dates
Prerequisites

No prior experience required. A basic understanding of spreadsheets is helpful but not necessary.

Donate to this project