When you use SQL you have to obey certain rules. Below I show you SQL Clauses list with logical (not physical execution) order of sql clauses or in other words sequence of clauses that you should follow in order to successfuly execute SQL statement.
SELECT -- which you use to specify the fields or calculated fields you want to return
FROM -- which you use to specify table or tables you want to use and usually includes joins.
WHERE -- which you use to filter rows
GROUP BY -- used to grouped together values using field or expression you specified
HAVING -- filters group by results with aggregate function (doesn't work on row by row basis like WHERE)
ORDER BY -- used to specify results order
The above our basic SQL Clauses in order you should use them. You don't have to use all of them but there are certain rules you should also follow:
1) SELECT is mandatory
2) FROM is used in most cases (sometimes you can use only select with union without specific table)
3) WHERE you need SELECT & FROM to use WHERE (In SQL Server you can actually used WHERE with select without from but there is not much use of that)
4) GROUP BY -- You cannot used fields in SELECT that are not in group by unless you use aggregate function with them
5) HAVING -- working only if you use GROUP BY
6) ORDER BY -- You can use it at any time
Hope those simple rules with help you specify the correct order of your SQL Clauses.