![A stick figure smiling](/images/welcome.jpg)
Here's a preview from my zine, Become a SELECT Star!! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!
![Image of a comic. To read the full HTML alt text, click "read the transcript".](/images/uploads/sql-query-order.png)
read the transcript!
Conceptually, every step (like “WHERE
”) of a query transforms its input, like this:
cats
owner: 1 name: daisy
owner: 1 name: dragonsnap
owner: 3 name: buttercup
owner: 4 name: rose
WHERE owner = 1
owner: 1 name: daisy
owner: 1 name: dragonsnap
The query’s steps don’t happen in the order they’re written:
how the query’ is written
SELECT…
FROM + JOIN
WHERE …
GROUP BY …
HAVING …
ORDER BY…
LIMIT…
how you should think about it:
FROM + JOIN
↓
WHERE
↓
GROUP BY
↓
HAVING
↓
SELECT
↓
ORDER BY
↓
LIMIT
(In reality query execution is much more complicated than this. There are a lot of optimizations.)
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!