QUERY SYSTEMSFoundations

SQL Essentials

The reliable mental model every later chapter depends on — pick a topic on the left and its full breakdown loads here: what a table is, what one row means, how a query is shaped, and how to read a result like an engineer.

18 min readTopics chapter readerLevel · Easy
01 · Orientation

What You'll Master Here

which table, which rows, and which columns?

5 min · Topic 1 of 15

SQL is how you ask a database questions. This first chapter teaches the basics: what a table is, what one row means, how a query is put together, and how to actually read the answer instead of just trusting it.

We use one small pretend online-shop dataset the whole way through: customers, orders, and the items inside each order. Keeping the data familiar lets you focus on the SQL, not the business.

By the end you will be able to look at a table you have never seen, pick the columns you want, keep only the rows you want, deal with missing values safely, and say in plain words what your query returns.

Core mental model

Before anything fancy, a good query answers three questions: which table, which rows, and which columns?

Why data engineers care

Most day-to-day SQL is simple: look at a table, check your assumptions, and pull out the rows you need. Getting comfortable with these basics is what makes every later topic (joins, grouping, and so on) easy to learn.

table
A grid of data, like a spreadsheet: columns across the top, rows going down.
row
One record in a table, e.g. one order. What a row stands for is called its grain.
column
One piece of information every row has, like status or created_at. Each column holds one type of value.
result
The rows and columns a query gives back. Always take a look at it.

table: orders

order_idbuyer_idstatuscreated_at
10449refunded2026-01-31
10437paid2026-01-31
10427paid2026-01-30

the labels across the top are columns — each holds one kind of value

each line is one row — here, one order

Run a query and what comes back is a result — the same shape: rows and columns.

customers

one row per customer

key: customer_id

orders

one row per order

key: order_id

order_items

one row per item in an order

key: order_id + sku

A customer places many orders; each order contains many items. Notice the grain gets finer left to right.

A safe first inspection queryworked example
SQL
select                    -- pick which columns to show
  order_id,               -- unique id of each order
  buyer_id,               -- which customer placed it
  status,                 -- paid, pending, refunded, ...
  created_at              -- when the order was created
from orders               -- the table we're reading from
order by created_at desc  -- newest orders first
limit 5;                  -- show only the first 5 rows
Result · 5 rows
order_idbuyer_idstatuscreated_at
10449refunded2026-01-31 18:04
10437paid2026-01-31 09:22
10427paid2026-01-30 21:10
10414pending2026-01-30 12:48
10402paid2026-01-29 15:31
Start narrow and ordered: a handful of recent rows tells you the shape of the table before you commit to anything. The -- notes are SQL comments; the database ignores them.
Common mistake

Writing a clever query before inspecting the table. You can produce a polished answer built on the wrong row set or a misread column.

Better habit

Inspect a small, ordered sample first.

Say the table grain out loud before querying.

Keep the first query readable before making it fancy.

Interview note

A strong beginner SQL answer is not fancy. It is clear about the table, the filter, the selected columns, and the assumptions being made.

Study tip

Use the topic menu on the left as a checklist. Each topic is a habit you should be able to demonstrate, not just recognize.

Remember this

Before optimizing syntax, be able to explain which table, which rows, and which columns your query touches.