SQL commands sequence

SQL commands sequence
0

#1

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.

@randelldawson


#2

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:


#3

WHERE comes before GROUP BY.

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


#4

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


#5

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

/*general rules*/

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

#6

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


#7