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 23F5852862 for ; Fri, 12 Aug 2005 15:05:40 -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 29960-04 for ; Fri, 12 Aug 2005 18:05:35 +0000 (GMT) Received: from mail.osl.com (216-21-133-98.ip.van.radiant.net [216.21.133.98]) by svr1.postgresql.org (Postfix) with ESMTP id 5978852E81 for ; Fri, 12 Aug 2005 15:05:33 -0300 (ADT) Received: from scottpj ([90.1.0.155]) (authenticated) by mail.osl.com (8.11.6/8.11.2) with ESMTP id j7CI5cc14968 for ; Fri, 12 Aug 2005 11:05:38 -0700 From: "Owen Jacobson" To: Subject: Re: SQL Newbie Date: Fri, 12 Aug 2005 11:05:26 -0700 Message-ID: <001601c59f68$6b2fff50$9b00015a@osl.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2910.0) Importance: Normal In-Reply-To: <20050812175529.82D7F24F3B9@smtp.nildram.co.uk> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=[FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200508/76 X-Sequence-Number: 22304 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 > ) > ) Worth noting that ORDER BY speed DESC LIMIT 1 is fundamentally the same as MAX (speed), except that MAX (speed) doesn't take advantage of any index present. This is a fairly common idiom but a self-described SQL Newbie may not see the equivalence instantly. -Owen