X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2F84052EBB for ; Fri, 12 Aug 2005 16:37:49 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40410-02 for ; Fri, 12 Aug 2005 19:37:47 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.197.194]) by svr1.postgresql.org (Postfix) with SMTP id D8C2352E98 for ; Fri, 12 Aug 2005 16:37:45 -0300 (ADT) Received: (qmail 10507 invoked by uid 500); 12 Aug 2005 19:39:23 -0000 Date: Fri, 12 Aug 2005 14:39:23 -0500 From: Bruno Wolff III To: Nick Stone Cc: 'Lane Van Ingen' , pgsql-sql@postgresql.org Subject: Re: SQL Newbie Message-ID: <20050812193923.GA10364@wolff.to> Mail-Followup-To: Bruno Wolff III , Nick Stone , 'Lane Van Ingen' , pgsql-sql@postgresql.org References: <20050812175529.82D7F24F3B9@smtp.nildram.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050812175529.82D7F24F3B9@smtp.nildram.co.uk> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 tagged_above=0 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200508/77 X-Sequence-Number: 22305 On Fri, Aug 12, 2005 at 18:57:34 +0100, Nick Stone wrote: > Hope this helps > > SELECT > * > FROM > speed_history as outside etc.. > WHERE > (speed = ( > SELECT > speed > FROM > speed_history as inside etc.. > WHERE > (outside.interface = inside.interface) > LIMIT 1 > ORDER BY > speed DESC > ) > ) > > Hopefully you get the idea - basically it's a corelated sub-query - very > useful > Note that you want to order by interface DESC, speed DESC in the subselect and have an index on (interface, speed) for this to really be efficient. I think 8.1 might be smart enough to use an index on (interface, speed) in the above case, but currently released versions won't.