Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id CA141B5FB1B for ; Wed, 1 Jun 2011 18:38:25 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 90618-04 for ; Wed, 1 Jun 2011 21:38:18 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id 23039B5F3E4 for ; Wed, 1 Jun 2011 18:38:17 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Wed, 01 Jun 2011 16:38:17 -0500 Message-Id: <4DE66AF8020000250003DFB6@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Wed, 01 Jun 2011 16:38:16 -0500 From: "Kevin Grittner" To: "CS DBA" , Subject: Re: Problem query References: <4DE69D92.5040407@consistentstate.com> In-Reply-To: <4DE69D92.5040407@consistentstate.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/7 X-Sequence-Number: 43940 CS DBA wrote: > The app wants to run a query like this: > > select count(pri_num) from max_xtrv_st_t > where pri_num in (select max(pri_num) from max_xtrv_st_t where 1=1 > group by tds_cx_ind, cxs_ind_2) Why not something simpler? There are a number of possibilities, and I don't claim this one is necessarily best (or even error free), but how about something like?: select count(*) from (select distinct max(pri_num) from max_xtrv_st_t group by tds_cx_ind, cxs_ind_2) x -Kevin