E-Learning Platform
0 of 139 builtAlways freeSign in
← Database Foundations I
2.01

What a Query Is

On this stop
  • Queries
  • What SQL is

Unit 1 left you standing in a library you can finally read: drawers, cards, pointers. Now for the part you actually came for — getting answers out. And the first rule of a well-run library is one you already follow in real life: you don't wander the shelves yourself. You ask the librarian.

Questions, made precise

A query is a question posed to a database. Not a vague one — a precise one: which facts, from which table, under which conditions. "Some student stuff" is not a query. "The names and ages of every student in the Music class, youngest first" — that's a query. The precision is the point: a database holding ten million rows can't read your mind, but it can execute an exact request against all ten million in the time it takes you to blink.

The librarian in our library is the database system itself — the tireless clerk who knows every drawer, never misfiles, and never gets bored of being asked. Your job in this unit is not to search. Your job is to phrase the request. The librarian does the walking.

SQL: the language of asking

Databases from dozens of makers all speak dialects of one asking language: SQL — Structured Query Language, said letter by letter, "ess-cue-ell" (some people say "sequel"; both are welcome at parties). It was designed in the 1970s to read almost like careful English, and it took over the world so completely that "can you write SQL?" is shorthand for "can you talk to databases?" Learn it once, use it near-everywhere.

Here is a real query, followed by what the librarian hands back. Don't worry about the grammar yet — next lesson takes it apart word by word. For now, read it the way you'd read a sentence in a language you're about to learn:

Up closeSQL
SELECT name, age
FROM students
WHERE age = 14;
Up closeText
name  | age
------+----
Sara  | 14
Amara | 14

Even squinting, you can guess most of it: select the name and age, from the students drawer, where the age is 14. SQL's keywords are written in capitals by convention — SELECT, FROM, WHERE — like polite stage directions, and the request ends with a semicolon, SQL's period.

The answer is always a table

Look at what came back: rows and columns. That's no accident, and it's the quietly beautiful idea inside SQL. You ask a question about tables, and the answer arrives as a table — smaller, rearranged, exactly the shape you asked for. The librarian doesn't hand you a shrug or an essay; they assemble a fresh tray of cards containing precisely your answer. Everything you learned about reading tables in Unit 1 applies, unchanged, to reading answers.

That loop — table in, question over it, table out — is the whole rhythm of this unit. Six more lessons, and each one adds a phrase to your librarian vocabulary: choosing columns, filtering rows, sorting piles, counting, and eventually asking one question across two drawers at once.

Next lesson: the two words every query in the world starts with.