How To Remember SQL Clause Ordering

Despite the fact that I've now been writing and tuning SQL statements for over half my life, I still don't feel like I'm an expert. Whenever I need a reminder of this, all I do is ask myself where a GROUP BY clause goes in a SQL query. Does it go before or after WHERE?

I tweeted my frustrations about this the other day, and got a very helpful reply:

Ooh! A mnemonic! And a pretty good one at that. The idea being that the first letter of each word of the sentence helps you remember something else, like the order of the major parts of a SELECT statement:

SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY

French fries
Though I agree the name Phillip not starting with an "F" can be a bit confusing. The name could be changed to Frederick easily enough.

This got me trying to think of one on my own.

Seasoned fries will give him obesity.

Maybe that's a little too intense. I'm not trying to pick on larger people.

Seasoned fries will give hypertension obviously.

A little better. Still health-related, but memorable nonetheless. And then I wondered if someone had built a tool for generating these. And because it's a big internet, of course someone has.

Enter the Mnemonic Generator! Type in the things you're trying to remember and it will generate a mnemonic phrase for them. I tried a few and here are some of the more amusing results:

Slimy Farnsworth Welcomed Glamorous Hot Outlaws.

Subliminal Fleshy Warriors Grabbed Hard Omelettes.

Ain't technology grand?

With these handy phrases, I now have no excuse for not remembering SQL clause ordering.