SQL commands sequence

SQL commands sequence


I knew that in SQL generally we write statements like this :

/* after creating the table */

SELECT something FROM table_name WHERE something something


SELECT something FROM table_name HAVING something something

The question I wanna ask is does it matter where do I put GROUP BY?

Can I add it at the end like this :

SELECT something FROM table_name WHERE something something GROUP BY something

Or I should add it in the middle?

SELECT something FROM table_name GROUP BY something WHERE something something

Does it really matter?

Thanks in advance.



I believe ‘where’ has to come before ‘group’. But that is an easy thing to test, so why not just try?

here’s a reference I found on this:


WHERE comes before GROUP BY.

If you look at the example I gave you in the other thread, you will see this in action.


Think this article may help you understand the diffs between where, having and group by in sql


so , in summary I can explain the syntax like this:

/*general rules*/



This post was flagged by the community and is temporarily hidden.