Lesson 154 of 1570
SQL Basics With AI
SELECT, WHERE, JOIN, GROUP BY. Four keywords run the data world. AI is excellent at SQL because it has read every StackOverflow answer ever.
Lesson map
What this lesson covers
Learning path
The main moves in order
- 1The Shape of a Query
- 2SELECT
- 3JOIN
- 4aggregate
Concept cluster
Terms to connect while reading
Section 1
The Shape of a Query
Every SELECT answers: from which tables, filtered how, grouped how, sorted how, limited to how many. Learn that shape and SQL becomes fill-in-the-blanks.
Primary keys, foreign keys, and an index on the foreign key. The minimum for a real app.
-- schema
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email TEXT UNIQUE NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
user_id INT REFERENCES users(id),
total NUMERIC(10,2) NOT NULL,
placed_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_orders_user ON orders(user_id);Top 5 spenders this month
JOIN, WHERE, GROUP BY, ORDER BY, LIMIT. The classic shape of a reporting query.
SELECT
u.email,
SUM(o.total)::NUMERIC(10,2) AS spent
FROM users u
JOIN orders o ON o.user_id = u.id
WHERE o.placed_at >= date_trunc('month', now())
GROUP BY u.email
ORDER BY spent DESC
LIMIT 5;The big idea: learn the query shape, keep indexes honest, and let AI draft while you verify with EXPLAIN.
End-of-lesson quiz
Check what stuck
15 questions · Score saves to your progress.
Tutor
Curious about “SQL Basics With AI”?
Ask anything about this lesson. I’ll answer using just what you’re reading — short, friendly, grounded.
Progress saved locally in this browser. Sign in to sync across devices.
Related lessons
Keep going
Builders · 30 min
Your First Git Commit, Explained
Git is a time machine for your code. Before we ship anything, let's learn the three commands that matter and what they actually do under the hood.
Builders · 45 min
Your First Capstone — Ship a Small Project
Bring it all together. Pick one of three starter projects, plan it, build it with AI, and deploy it. You are now a builder who ships.
Builders · 30 min
Python Functions — Writing Your Own Tools
A function is a reusable chunk of code with a name. You'll write three, add type hints, and let AI suggest better names and docstrings.
