HotSetsJoiningGroupingAbsent ValuesRow CountsSanity Checks
Latest A question you can say out loud is a question you can check afterwards.
First Principles

The Beginner's Real Problem Is Trust, Not Typing

Learning to ask a database a question is easy enough. Learning to believe the answer, and to know when you should not, is the part nobody teaches you.

There is a moment that arrives for every beginner, usually late in the afternoon, when the answer finally appears. A number sits on the screen. It looks plausible. It has the right number of digits and it does not have an error attached to it. And in that moment you have to decide something that no manual will decide for you: do you believe it? Most people say yes, because the effort of getting there has already been considerable and because a number that appears looks a great deal like a number that is true. That decision, made quickly and quietly, is where nearly all real trouble begins.

This publication exists for that moment. Not for the mechanics of writing the request, which you can pick up from any tutorial in a weekend, but for the harder discipline of knowing what you actually asked and whether the shape of the answer matches the shape of the question. Those two things come apart more often than beginners expect. You can ask a perfectly well formed question and get a perfectly well formed answer to a slightly different question, and nothing anywhere will warn you. There is no red underline for a wrong idea.

Continue reading

Thinking In Sets

The Question Comes First, The Query Comes Second

Most bad answers begin as vague questions that nobody bothered to make precise.

Why Order Feels Missing And Why That Is Fine

Beginners often feel unsettled that results come back in no reliable arrangement, but the unease points at something useful.

Lining Tables Up

The Quiet Multiplication That Doubles Your Totals

When the value you match on repeats, records combine with each other and your result grows without any warning.

Dropped Or Kept: The Honest Choice About Unmatched Rows

Records with no partner on the other side either vanish or stay with gaps, and choosing carelessly rewrites your findings.

Summarising Safely

An Average Can Be Correct And Still Useless

Arithmetic that is beyond dispute can still produce a figure that misleads everybody who reads it.

Never Summarise Data You Have Already Duplicated

The two most common errors in this subject combine into something considerably worse than either alone.

Trusting The Answer

A Total That Looks Right Can Still Be Wrong

Plausibility is the weakest possible evidence, and it is the evidence most people quietly rely on.

Check Your Answer Against A Number You Already Know

The strongest verification available to a beginner is a figure that came from somewhere else entirely.

About SQL Child

SQL Child is a publication about asking a database a question and being able to trust the answer that comes back. The name refers to a child record, the ordinary relational idea of a detail that belongs to something larger: an order belonging to a customer, a line belonging to an invoice. That relationship, the fact that one thing can have many things hanging off it, is the source of most of the confusion this magazine sets out to clear up, and it seemed a fitting thing to be named after. Nothing here is about anything else.

The writing is aimed at the adult beginner who did not plan on this. You have a job to do, somebody has given you access to a database, and the answers you need are somewhere inside it. You are not training to be a specialist and you do not need to become one. You need to be able to get a number out, understand precisely what it represents, and put your name next to it without a quiet feeling of dread. That is an achievable standard and it is what everything published here is written to serve.

There is a deliberate omission you will notice immediately: no code appears anywhere. That is not an oversight and it is not a limitation of the format. The mechanics of writing a request are the easiest part of this subject and they are already documented exhaustively everywhere. The thinking is the hard part, it transfers between every system you will ever touch, and it is almost never taught on its own. So we teach the thinking, in plain words, and leave the particular dialect to whichever manual sits beside your keyboard.