TOPIC 02/3016 MINNOT STARTED

SQL for BAs: SELECT and WHERE

Ask a database questions with SELECT and WHERE. Learn conditions, null, sorting, limits, the second-highest trick, the five kinds of SQL statement and safe habits for analysts.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: The librarian. You ask a librarian, "Give me every book by one author published after 2020." The librarian walks to the shelves, picks out the books that fit, and brings them to you. A good librarian also understands a vague ask, such as "something about boats".

A database is not so kind. It does exactly what the question says, so every word must be exact.

Daily List is a made-up to-do app (SYNTHETIC / TRAINING ONLY). Its tasks sit in a table called tasks. Sam, the , wants to know which open tasks are due on the example date. Sam writes the question in (Structured Query Language).

SELECT title FROM tasks WHERE status = 'open' AND due_date = '2026-10-20';

What it is: SQL (Structured Query Language) is a language for asking questions of a database. A database keeps its data in tables. A table is a grid where each row is one thing, such as one task, and each column is one fact about it, such as its title. SELECT picks the columns to show, and WHERE keeps only the rows that pass a test. You type SQL into a tool that is connected to a database such as PostgreSQL, MySQL or SQLite. WHERE is easy to mix up with HAVING, which filters groups of rows after they are counted.

Why it matters: Without SQL, Sam must wait for a developer each time Nina, the , asks "how many tasks are due on the example date?". With SELECT and WHERE, Sam can check a report figure or a screen against the real data in minutes. A wrong WHERE gives a neat answer that is wrong, so Sam also learns to count the rows that come back.

The librarian understands a vague ask. SQL does not.

PLAIN WORDS · 1 in this section
sqlite
a small free database tool

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the work.

THE REAL JOB The picture helps a newcomer remember that a query is a precise ask, and that the database does not guess what was meant.

  1. SELECT what
  2. FROM where
  3. WHERE which rows
  4. ORDER BY how
  5. Check the row count
Building a query

HOW THE PICTURE MAPS

How each part of the picture matches the work
In the pictureIn the work
Asking for books by one authorSELECT, choosing what to show
The shelves the librarian walks toFROM, the table to look in
After a chosen year as a test on each bookWHERE, the condition on each row
A book with no printed yearA NULL, which ordinary equality cannot match; IS NULL can
Counting the books you gotChecking the number of rows

WHERE THIS PICTURE STOPS

  • A librarian understands a vague ask, but Structured Query Language (SQL) does not.
  • A librarian points out a book with no year. Structured Query Language (SQL) leaves it out of an ordinary comparison unless missing values are handled.
  • A librarian only fetches books. Structured Query Language (SQL) can also change them if given the power.

HOOK

Pick the columns, name the shelf, test each row.

REMEMBER IT THIS WAY

A rule of thumb: if you see this, think that.

If a row has no value in the tested column, a test quietly leaves it out, so check blanks.

What each part of the trick stands for
In the trickWhat it stands for
blanka book with no year
WHEREa test

A column that must be filled in cannot hide rows this way.

TELL A FRIEND

Structured Query Language () asks a database questions. SELECT chooses what to show, FROM names the table, and WHERE keeps only the rows that pass a test, with null needing IS NULL.

OFTEN MIXED UP WITH Entities and relationships (ERD). That topic shows the things and links in the data. This one asks the database questions about them.

PRACTISE AND KEEP

Sources for this topic — 6 sources
  1. Market practice

    SELECT command reference (PostgreSQL documentation) ↗ — PostgreSQL · PostgreSQL 18, SELECT: WHERE/HAVING/output aliases, functional dependence, NULL ordering and LIMIT; publisher page opened6November 2026. Dialect scope explicit.

    SELECT: WHERE/HAVING/output aliases, functional dependence, NULL ordering and LIMIT. PostgreSQL18 implementation, not a universal SQL mandate. · Checked 2026-11-06

    PostgreSQL18 publisher documentation opened on6November2026: SELECT: WHERE/HAVING/output aliases, functional dependence, NULL ordering and LIMIT. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.

  2. Market practice

    Conditional expressions (PostgreSQL documentation) ↗ — PostgreSQL · PostgreSQL 18, §9.18 CASE/COALESCE/NULLIF; publisher page opened6November 2026. Dialect scope explicit.

    §9.18 CASE/COALESCE/NULLIF. PostgreSQL18 implementation, not a universal SQL mandate. · Checked 2026-11-06

    PostgreSQL18 publisher documentation opened on6November2026: §9.18 CASE/COALESCE/NULLIF. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.

  3. Market practice

    SQLite: SQL expressions ↗ — SQLite project · SQLite: SQL expressions; CASE/BETWEEN/IN/EXISTS, scalar cardinality, NULL-safe equality and parameter values. Publisher page opened6November 2026.

    CASE/BETWEEN/IN/EXISTS, scalar cardinality, NULL-safe equality and parameter values. · Checked 2026-11-06

    Publisher documentation opened on6November2026. Engine/version scope is explicit; other database implementations may differ. Teaching queries are synthetic, not a required publisher template.

  4. Market practice

    PostgreSQL18: SET TRANSACTION ↗ — PostgreSQL Global Development Group · PostgreSQL 18: SET TRANSACTION; Read-only mode and isolation/snapshot characteristics. Publisher page opened6November 2026.

    Read-only mode and isolation/snapshot characteristics. · Checked 2026-11-06

    Publisher documentation opened on6November2026. Engine/version scope is explicit; other database implementations may differ. Teaching queries are synthetic, not a required publisher template.

  5. Market practice

    PostgreSQL18: PREPARE ↗ — PostgreSQL Global Development Group · PostgreSQL 18: PREPARE; Parameter values separate from statement text and placeholder syntax; session scope. Publisher page opened6November 2026.

    Parameter values separate from statement text and placeholder syntax; session scope. · Checked 2026-11-06

    Publisher documentation opened on6November2026. Engine/version scope is explicit; other database implementations may differ. Teaching queries are synthetic, not a required publisher template.

  6. Simplified educational illustration

    Payments Signal editorial teaching models — Payments Signal

    This site's own simplified teaching models. · Checked 2026-07-12

    What this simplifies: Daily List people, data and exercises are invented for teaching. Query results belong to the declared fixture and database version. Authorization, business identity, time bounds and unknown-value policy must be agreed in context; no universal mandatory query template is implied.

    Used wherever diagrams, scenarios, figures, or example values are didactic constructions rather than sourced facts; every such use carries a simplifications disclosure. All people, companies, banks, and list entries in examples are fictional.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.