Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Having without group by clause

Having without group by clause

From: <krishnanand_at_hotmail.com>
Date: 1997/11/25
Message-ID: <880519648.6679@dejanews.com>#1/1

Hi,

   Consider 2 tables: X & Y with 2 columns each as shown below:

    X                                               Y
-----------                                 -----------------
 I  |  II                                     III   |  IV
----|------                                 --------|--------
 10 |   A                                      10   |   1
 20 |   B                                      10   |   2
-----------                                 ------------------


  If I give the Query as:

(1) Select I,II from X

     where exists
     ( select III from Y
       where X.I=Y.III
       having sum(IV) > 1 ) ;

  The Query works fine . One thing to NOTICE here is that, in the subquery the column being selected & the column being aggregated in the having clause are different !!!

  I believe in the subquery , for X.I=10 it will fetch 2 rows ( (10,1) (10,2) ) treat them as a group ( taking III as the grouping column ) & sum on the IV column. To test this

 I did something else, as follows :

(2) I executed the queries :

  (a) select III from Y having sum(IV) > 1 ;

  (b) select III from Y where 1>2 having sum(IV) > 1 ; --- thinking that

          WHERE clause may be necessary. BUT BOTH FAIL.

   My question is : How is the subquery situation in (1) DIFFERENT from the situation in (2).

 Please reply by EMail also.

 Thanx.

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet
Received on Tue Nov 25 1997 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US