Loading lesson…
SELECT, WHERE, JOIN, GROUP BY. Four keywords run the data world. AI is excellent at SQL because it has read every StackOverflow answer ever.
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.
-- 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);Primary keys, foreign keys, and an index on the foreign key. The minimum for a real app.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;JOIN, WHERE, GROUP BY, ORDER BY, LIMIT. The classic shape of a reporting query.The big idea: learn the query shape, keep indexes honest, and let AI draft while you verify with EXPLAIN.
15 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-progx-sql-basics-builders
Which SQL keyword is used to filter rows based on specific conditions?
What does a Seq Scan (sequential scan) in EXPLAIN output typically indicate?
Why is concatenating user input directly into SQL queries dangerous?
Which SQL keyword is used to combine rows from two or more tables based on a related column?
What does the GROUP BY clause do in a SQL query?
When you run EXPLAIN ANALYZE on a slow query, what should you look for first?
What is a parameterized query?
The lesson describes SQL queries having a 'shape.' What does this shape represent?
Why is AI considered particularly good at writing SQL?
What does the LIMIT clause control in a SQL query?
Which of the following is a security best practice when building SQL queries with user input?
You notice a query scanning 50 million rows with a Seq Scan. What should you do?
What must be true about the 'shape' of every SELECT query?
Your AI-generated SQL query works but runs slowly on a large table. What should you verify?
Which four SQL keywords does the lesson identify as fundamental to data queries?