What a Query Really Is
We've built and connected our tidy tables. Now we finally ask them a question. A query is a request you hand the database, written carefully enough that it knows exactly what to fetch. You don't scroll through the rows yourself, hoping to spot what you need. You describe what you want, and the database goes and gathers it.
Think of a deli counter. You don't climb behind the glass and rummage. You fill out a little slip: which case to look in, what counts as a match, and what to actually hand back. Someone who knows where everything is brings back only that. A query is that order slip for your data.
A request, not a scroll-and-search
Searching a spreadsheet by eye is like flipping every page of an address book hoping a name jumps out. A query is the opposite move. You tell a clerk "everyone in Albany," and a clean list comes back. You never touched the pages.
That shift matters most when the data is big. Ten rows you can scan. Ten thousand you cannot. The query stays just as easy either way, because you're describing the rows you want rather than hunting for them one at a time.
The three things almost every query says
Strip away the technical wording and nearly every query says the same three things.
Pick a table. Which case are you looking in — customers, or orders? A query starts by naming one table to work from.
Set a condition for which rows count. This is the heart of it. "City is Boston." "Price is over fifty." The condition is a test each row must pass. Rows that match are handed to you; rows that don't are quietly left behind. You can stack conditions, too — "in Boston and signed up this year" — and each one narrows the catch, like adding words to your deli order until only the thing you want remains.
Choose which columns to return. You rarely want every column. Maybe just the name and email, not the whole history. You pick the facts you want back, and the rest stay behind the glass.
Pick a table, set the condition, choose the columns. "From orders, where the price is over fifty, show the order number and date." That sentence is a query, just in everyday clothes.
You already ask queries
Here's the part that surprises people: you query things all day without the word.
When you search your email for unread, from Sarah, this month, you just wrote a query. The table is your inbox. The condition is "unread and from Sarah and from this month." The columns are the sender, subject, and date each result shows you.
When you shop online and filter shoes, size 9, under $80, in stock, that's a query too. Pick the table (products), set four conditions, get back only the matches with their photo and price. You weren't scrolling the whole warehouse — you handed over a slip and the store brought back the matches.
The grown-up version is written in a language built for it; you may have heard the name SQL. But you don't need that language to understand what's happening. Something asks a clear question, and the data answers with just the matching rows.
Your turn
Open your email and search for messages from one specific person, sent this year. Now name the three parts out loud: the table is your inbox, the condition is "from that person and from this year," and the columns are what each result shows — sender, subject, date.
Do the same on a shopping site with two or three filters. Once you can spot the table, the condition, and the columns, you can read any query.
Next we'll see how the database answers so fast, even across millions of rows, using a trick borrowed from the back of a book. 🔦
Stuck or curious?
Ask Pip about this lesson — tap the porthole bottom-right.