SFWGHO – A Way to Remember the Order of Commands in SQL

Question – SFWGHO

When writing T-SQL, Microsoft uses the SQL database language, and the commands must be arranged in a certain order. This is:

– SELECT (Select Data)

– FROM (Describe from which table to get data)

– WHERE (any filter condition)

– GROUP BY (specify any aggregation to be performed) [19659003] – HAVING (any filtering performed on aggregated data)

– ORDER BY (displays the order of the final line)

It is important to place these commands in the correct order, otherwise you will get a syntax error. The acronym for the command is SFWGHO, so it's really just a question of finding a way to remember this series of letters.

Solution

When he first encountered this problem, the author of this article searched online for acronyms. I found a website in progress, one of the contestants:

The slippery fish will decorate the hungry killer whale

Of course there must be better acronyms ! A little reflection reflects the following thoughts:

Six obese wife total husband

sweaty feet will emit a terrible smell

Among them, the second seems to be better (it Of course better taste!). Therefore, we recommend how to remember the order of the commands in SQL:

SWEATY or SELECT

FEET or FROM

will or

GIVE or GROUP BY

HORRIBLE or HAVING

ODORS or ORDER BY

So now there is no reason to make the order of SQL commands wrong, we just need to find a way to remember to keep the comma in the correct position…



Source by Andy J Brown