Lesson 154 of 1455
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.
Builders · AI-Assisted Coding · ~21 min read
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
6 questions · Score saves to your progress.
Lesson help
Questions are best handled with a grown-up here.
For this age range, Tendril keeps freeform AI chat paused until parent/guardian consent and child-safe moderation are fully verified. Use the quiz, notes, and related lessons below, or ask a parent, guardian, teacher, or librarian to work through the question with you.
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.
