Reading a Query You Did Not Write

Read it in evaluation order, not written order. FROM first: which tables, and how are they joined? Then WHERE: which rows survive. Then GROUP BY: what is a group here. Then HAVING, then SELECT, then ORDER BY.

Doing that consistently turns a forty-line query from something intimidating into six small questions.

Four questions to ask of any query someone hands you.

What is one row of the result? If you cannot say that in a sentence, you do not understand it yet.

Could any join multiply rows, and does any SUM depend on that?

Is there a NULL in any filtered or joined column?

Is the ordering stable, or could two runs disagree?

Those four catch most of what actually goes wrong.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Practice Test →
← Back