dbTalk Databases Forums  

Scalar Subquery in GROUP BY and HAVING clause

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Scalar Subquery in GROUP BY and HAVING clause in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
 
Posts: n/a

Default Scalar Subquery in GROUP BY and HAVING clause - 12-20-2004 , 03:20 AM






According to Oracle's documentation (SQL reference), GROUP BY and HAVING
clause cannot have scalar subquery. However, I tested with Oracle 9.2
personal edition and found that the following query can be executed without
error. The query does contain a scalar subquery in its HAVING clause.
This query is actually taken from Oreilly's Mastering Oracle SQL 2nd edition
chapter 5 section 5.2.1.

SELECT sales_emp_id, COUNT(*)
FROM cust_order
GROUP BY sales_emp_id
HAVING COUNT(*) = (SELECT MAX(COUNT(*))
FROM cust_order
GROUP BY sales_emp_id);

Can anyone help me to explain the discrepancy?





Reply With Quote
  #2  
Old   
Mark D Powell
 
Posts: n/a

Default Re: Scalar Subquery in GROUP BY and HAVING clause - 12-20-2004 , 08:19 AM






It is a definite error in the manuals. I am not sure but I had thought
that the term scalar subquery had been applied to select statements in
the select list of another query: select col1, (select colb from table
2 ...), col3 when Oracle first introduced it. Subqueries of the form
in the example were just normal subqueries. The definition that
appears in the 9.2 and 10g SQL manual under the topic "Scalar Subquery
Expressions" makes no such distiction. So either the list about where
the scalar subqueries are legal is wrong or the definition of a scalar
subquery requires clarification.

IMHO -- Mark D Powell --


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.