I been going thru some of the sql syntax to study for the oracle sql exam, I found something rather confusing
based on the official references, the select syntax is as follow :
SELECT
[ hint ]
[ { { DISTINCT | UNIQUE } | ALL } ]
select_list
FROM { table_reference | join_clause | ( join_clause ) }
[ , { table_reference | join_clause | (join_clause) } ] ...
[ where_clause ]
[ hierarchical_query_clause ]
[ group_by_clause ]
[ HAVING condition ]
[ model_clause ]
based on this you cannot have the HAVING clause before the GROUP BY clause . However if i were to execute the following sql in the test server :
select
department_id , count (*)
from
employees
having
count(*) > 6
group by
department_id ;
it does not produce a syntax error , can some one help explain this ? I don't like to think that the reference docs is wrong , but if so I need some confirmation.
As stated here: