X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 11E119FA5C8 for ; Mon, 12 Jun 2006 17:20:09 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 04832-04 for ; Mon, 12 Jun 2006 17:19:59 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web33303.mail.mud.yahoo.com (web33303.mail.mud.yahoo.com [68.142.206.118]) by postgresql.org (Postfix) with SMTP id 985409FA159 for ; Mon, 12 Jun 2006 17:19:58 -0300 (ADT) Received: (qmail 96032 invoked by uid 60001); 12 Jun 2006 20:19:55 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=zVNKalnkBA9okm5wdxx9Yyx/kJGu0kWKaJmsOGKPd6IrdEWQbRdJ1xB4PD9R5bcuVBDhi3YZNrsT90mYLmvAibkgAnU6Y78P7B6sGjrpvc5k0aZ56U18uZ+DBKywNRsGSasTQY7C9Y2lh0nsJI/neV5ndq1TB5uMPGIvz5SsKRs= ; Message-ID: <20060612201955.96030.qmail@web33303.mail.mud.yahoo.com> Received: from [12.9.179.126] by web33303.mail.mud.yahoo.com via HTTP; Mon, 12 Jun 2006 13:19:55 PDT Date: Mon, 12 Jun 2006 13:19:55 -0700 (PDT) From: Subject: Re: Refactor Query... SOLVED To: operationsengineer1@yahoo.com, "pgsql-sql@postgresql.org" In-Reply-To: <20060612181142.30113.qmail@web33304.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/123 X-Sequence-Number: 25359 --- operationsengineer1@yahoo.com wrote: > hi all, > > i'm trying to refactor this query: > > http://www.rafb.net/paste/results/RnkFWZ46.html > > i've added notes to make its function a bit more > clear. i have trie dto refactor it to get rid of > the > "distinct on" function, but i've had no luck. > > due to all the WHERE clauses, i can't figure out how > to do an inner join with something like this: > > select > max(t_inspect_result.inspect_result_timestamp) > as mstamp, > t_inspect_result.inspect_id > from t_inspect_result > group by t_inspect_result.inspect_id > ) AS b > > thanks in advance... these queries (i have them all over my app!) are getting complex and i'm being challenged to keep everything in order. this is the final result: http://www.rafb.net/paste/results/pnvLSs30.html here's a special thanks to all who have helped on this and other recent query problems. thank you! i *rally* appreciate the chared insight and guidance. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com