SFWGHO – A Method to Bear in mind the Order of Instructions in SQL

0
11

The Drawback – SFWGHO

When writing T-SQL, Microsoft’s tackle the SQL database language, the instructions have to come back in a sure order. That is:

– SELECT (deciding on knowledge)

– FROM (stating which desk to get knowledge from)

– WHERE (any filtering situations)

– GROUP BY (specifying any aggregation to carry out)

– HAVING (any filtering to carry out on aggregated knowledge)

– ORDER BY (which order to show the ultimate rows in)

It’s important that you simply put these instructions in the correct order, in any other case you may get a syntax error. The acronym for the instructions is SFWGHO, so it is actually only a query of discovering a approach to keep in mind this collection of letters.

Options

When he first met this drawback, the writer of this text trawled the Web for acronyms. I discovered one website which was operating a contest, with one entrant:

Slippery Fish Will Garnish Hungry Orcas

Absolutely there have to be higher acronyms than that! A little bit reflection got here up with the next concepts:

Six Fats Wives Gross Husbands Out

Sweaty Toes Will Give Horrible Odours

Out of those, the second appears higher (it is definitely in higher style!). So right here is our suggestion for how you can keep in mind the order of instructions in SQL:

SWEATY or SELECT

FEET or FROM

WILL or WHERE

GIVE or GROUP BY

HORRIBLE or HAVING

ODOURS or ORDER BY

So now there is no excuse for getting the order of SQL instructions incorrect, we simply have to discover a approach to keep in mind to place commas in the correct place on a regular basis…



Supply by Andy J Brown

LEAVE A REPLY

Please enter your comment!
Please enter your name here