SQL (Structured Query Language) filtering, sorting and totals for testers
Most checks are a filter and a count. Learn WHERE with AND, OR, IN, BETWEEN and LIKE, then ORDER BY, LIMIT, DISTINCT and the five totals.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: sorting a pile of receipts. You pick out the receipts that match. This month, between two amounts, from one shop. You put them in date order. Then you count them and add them up.
Daily List is a to-do list app. Tom, the tester, uses the same moves on rows. He wants a fast check, and he wants a number he can compare with the screen.
What it is: A WHERE clause is the test that keeps some rows and drops the rest. (Structured Query Language) is the language the test is written in. A table is a grid, a row is one item, and a column is one fact about that item. The here are AND, OR, IN, BETWEEN and LIKE. WHERE is easy to mix up with HAVING. WHERE tests single rows. HAVING tests groups after they are counted.
Why it matters: Most of Tom's checks are a filter and a count. A filter that is almost right still returns a neat number. Nina, the product owner, may trust that number. Tom learns the operators so the number means what the question asked.
(SYNTHETIC / TRAINING ONLY: Daily List and every person named in this lesson are invented.)
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB Picking receipts, putting them in order and adding them up.
- Filter
- Sort
- Total
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| Picking receipts | WHERE |
| Date order | ORDER BY |
| Only the top few | LIMIT |
| Adding up | SUM and COUNT |
WHERE THIS PICTURE STOPS
- Receipts are few, but rows are many.
- A pile has an order, but rows do not unless you ask.
- You see the receipt, but NULL is invisible.
HOOK
Filter, sort, total.
TELL A FRIEND
Receipts: pick, order, add up.
OFTEN MIXED UP WITH Looking at data with SQL SELECT. That topic reads a table with simple filters. This one adds the full set of filters, sorting and totals.
PRACTISE AND KEEP
Sources for this topic — 2 sources
- Market practice
Gotcha: SQL aggregate functions and NULL ↗ — SQLServerCentral · SQLServerCentral article: aggregate functions skip nulls, except COUNT(*) (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Implementation-specific
PostgreSQL documentation ↗ — The PostgreSQL Global Development Group · PostgreSQL 18 official manual, opened 2026-11-06: queries-table-expressions, queries-limit, functions-aggregate and functions-matching. Supports only PostgreSQL behavior; earlier execution evidence remains separately versioned.
An implementation, not the standard — which is the point. ISO/IEC 9075-2 is paywalled, and this documents the same constructs in text anybody can open. Its isolation-level chapter attributes to the standard explicitly, so it can carry a standard-level claim as long as the citation says which document it is quoting.
Cited as market practice rather than an official standard by kind: an engine's manual is authoritative about that engine and is not the obligation. Where a question turns on behaviour PostgreSQL chose rather than behaviour SQL requires, the answer has to say so.
One correction carried here because it circulates widely: the sentence "The fundamental difference between WHERE and HAVING…", quoted all over the internet as PostgreSQL documentation, is not in the current documentation. It was searched for in the source tree and is not there.
Read through a mirror, because the publisher's own domain could not be fetched (a reachability gap, not a statement about the publisher). A 403 there is a policy refusal and says nothing about whether the document exists or is reachable elsewhere.
Anyone on an unrestricted network should open the canonical URL above and confirm the section and page numbers cited against it. Every claim drawn from this entry is written so that it can be checked against a numbered page.
Read from the
postgres/postgresdocumentation source tree (doc/src/sgml), which the project itself maintains and which carries the section ids the published URLs are derived from — so a cited section id can be checked against the rendered page.
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.