Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 97430475C45 for ; Tue, 26 Nov 2002 08:16:45 -0500 (EST) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id BC3AA475ADE for ; Tue, 26 Nov 2002 08:16:44 -0500 (EST) Received: by news.hub.org (Postfix, from userid 8) id 8144143A62B; Tue, 26 Nov 2002 08:16:44 -0500 (EST) From: "Zuev Dmitry" X-Newsgroups: comp.databases.postgresql.sql Subject: help on sql query Date: Tue, 26 Nov 2002 19:14:07 +0600 Organization: Rinet Corp. News Service, Novosibirsk, Russia Lines: 33 Message-ID: X-Complaints-To: abuse@news.nsk.su X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 To: pgsql-sql@postgresql.org X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/381 X-Sequence-Number: 10523 Suppose you have a table T: ---------------------- A B ---------------------- 1 '111' 2 '222' ---------------------- How do you select A and B of the record with A maximum? The desirable result therefore is (2, '222') The two variants I could grow with are: 1) SELECT A, B FROM T ORDER BY A DESC LIMIT 1 2) SELECT A, B FROM T WHERE A IN (SELECT MAX(A) FROM T) What do yo think of the queries above? And give me the better implementation if possible. __________________________________________________________________ Dmitry Vitalievitch ICQ#: 11000008 Current ICQ status: + More ways to contact me __________________________________________________________________