SELECT, WHERE & Friends: Querying Basics
You've got a database. Somewhere in it are the rows you actually need — the user who can't log in, the orders from last Tuesday, the one record someone asked you to fix "real quick." SQL is how you ask for them. But staring at a blank query window, it's easy to feel like you're supposed to already know the magic words.
There aren't magic words. There's a small, learnable shape that almost every query follows, and once you can see that shape, you can reason your way to the data instead of guessing. This guide walks you through it calmly: how to ask for data, how to narrow it down to exactly what you want, and how to change it — including the one mistake that has ended a few people's afternoons (and we'll make sure it never ends yours).
We'll use one small example table the whole way through — a users table — so you're always learning
the idea, not re-learning a new dataset.
How to read this
- Need to grab some data right now? Start with Phase 1: Asking for Data — it's the core query shape and you'll be productive by the end of it.
- Want it to finally make sense? Read in order. Each phase builds on the last: ask for data, then narrow it, then change it.
The phases
- Asking for Data: SELECT ... FROM — the shape every query starts from, picking columns vs. grabbing everything, and how to read the result set.
- Filtering & Sorting: WHERE, ORDER BY, LIMIT — narrowing down to
the rows you want (
=,>,LIKE,IN,AND/OR), ordering them, and taking only the top few. Includes theNULLtrap that confuses everyone. - Changing Data: INSERT, UPDATE, DELETE — adding rows, modifying them, and
removing them — and the missing-
WHEREaccident that rewrites or erases your whole table, plus how to never let it stick.
This guide is about the day-one querying you'll reach for constantly. Joining data across multiple tables, grouping and counting with
GROUP BY, and subqueries are their own topics — they live in follow-up guides like SQL Joins, Explained, so this one stays focused and finishable.
Related reading: What a Database Actually Is · Relationships & Keys · SQL Joins, Explained