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 BC1EC9FA3CD for ; Mon, 12 Jun 2006 15:11:49 -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 86932-01 for ; Mon, 12 Jun 2006 15:11:44 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web33304.mail.mud.yahoo.com (web33304.mail.mud.yahoo.com [68.142.206.119]) by postgresql.org (Postfix) with SMTP id E482F9FA159 for ; Mon, 12 Jun 2006 15:11:45 -0300 (ADT) Received: (qmail 30115 invoked by uid 60001); 12 Jun 2006 18:11:42 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=pF/wlxAV3UK46AxzqkIWXMogWhPZhGypAz24G2KFRW/0GU1oHY0lR1BGyutyrP9F5BeV4FZjXOn6eY9IHNvJ5gKnusVZKVKQC9OlfXodzjq+T6UKq+mmXBjTzG/qs2n5f4xqfj/h15OPXEcGgFAlmQwBD76rZOopr2xDGJRVY4I= ; Message-ID: <20060612181142.30113.qmail@web33304.mail.mud.yahoo.com> Received: from [12.9.179.126] by web33304.mail.mud.yahoo.com via HTTP; Mon, 12 Jun 2006 11:11:42 PDT Date: Mon, 12 Jun 2006 11:11:42 -0700 (PDT) From: Subject: Refactor Query... To: "pgsql-sql@postgresql.org" 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/122 X-Sequence-Number: 25358 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... __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com