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

or

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.

@camperextraordinaire

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:

1 Like

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*/

SELECT ...
FROM...
WHERE...
GROUP BY...
HAVING...