Difference between "HAVING ... GROUP BY" and "GROUP BY ... HAVING"

group-by, having, oracle, sql, syntax

Solution

As documented, there is no difference. People are just used to seeing HAVING after GROUP BY.

http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_10002.htm#SQLRF20040

Specify GROUP BY and HAVING after the where_clause and hierarchical_query_clause. If you specify both GROUP BY and HAVING, then they can appear in either order.

http://sqlfiddle.com/#!4/66e33/1

Problem

I have got the table MYTABLE with 2 columns: A and B I have got the following pieces of the code: ``` SELECT MYTABLE.A FROM MYTABLE HAVING SUM(MYTABLE.B) > 100 GROUP BY MYTABLE.A ``` and ``` SELECT MYTABLE.A FROM MYTABLE GROUP BY MYTABLE.A HAVING SUM(MYTABLE.B) > 100 ``` Is it the same? Is it possible that these 2 codes will return diffrent sets of results? Thank you in advance

Original source