Received: from SRV.CTLNO.COM (srv.ctlno.com [204.252.218.112]) by hub.org (8.9.2/8.9.1) with ESMTP id NAA05209; Tue, 23 Mar 1999 13:46:12 -0500 (EST) (envelope-from matt@ctlno.com) Received: by srv.ctlno.com with Internet Mail Service (5.0.1457.3) id ; Tue, 23 Mar 1999 12:46:11 -0600 Message-ID: From: Matthew To: "'pgsql-general@hub.org'" , "'pgsql-interfaces@hub.org'" Subject: Problem using Having in a sub-query wit the Count function. Date: Tue, 23 Mar 1999 12:46:10 -0600 X-Priority: 3 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.0.1457.3) Content-Type: text/plain > We are trying to execute a query that has several sub-queries embedded > in it. Below is a snippet of the sql code. > > "Select ordnum from ordinace where dept='Finance' and ordnum in > (Select ordnum from squareview where square='A') and ordnum in (select > ordnum from keywordview where keyword='Parade' or keyword='Public > Gathering' group by ordnum having count(ordnum) =2)" > > The two tables in the sub-queries (squareview and keywordview) or > views created between two tables. > There are roughly about 20000 records in the keywordview view. > > When we execute the query, failing at the keywordview subquery, saying > the aggregate function in the having clause must appear on the right > side. (?) When we take the having clause out, and strictly have the > group by, it takes 30secs to 3mins. to return with the valid > recordset. > > The funny thing is, as a stand alone query on it's own, the > keywordview query works fine. It's very quick and has no problem with > the having clause. > > I was wondering if anyone else has either had this problme using > aggregate functions with the having clause in a subquery, or could > anyone give me any information of successfully executing something > similar to this. > > Any infomation would be appreciated. > > Thanks in advance, > > Steve > steve@ctlno.com