Received: from acheron.rime.com.au (albatr.lnk.telstra.net [139.130.54.222]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id e9UEVUC30538 for ; Mon, 30 Oct 2000 09:31:31 -0500 (EST) (envelope-from pjw@rhyme.com.au) Received: from oberon (Oberon.rime.com.au [203.8.195.100]) by acheron.rime.com.au (8.9.3/8.9.3) with SMTP id BAA17604; Tue, 31 Oct 2000 01:31:08 +1100 Message-Id: <3.0.5.32.20001031013120.028dd500@mail.rhyme.com.au> X-Sender: pjw@mail.rhyme.com.au X-Mailer: QUALCOMM Windows Eudora Pro Version 3.0.5 (32) Date: Tue, 31 Oct 2000 01:31:20 +1100 To: Lengyel Ferenc , "'pgsql-sql@postgresql.org'" From: Philip Warner Subject: Re: In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Archive-Number: 200010/9 X-Sequence-Number: 9 At 13:36 30/10/00 +0100, Lengyel Ferenc wrote: >Hello everybody! >I need some help with a simple query. >I've got a problem with getting a maximum value from a very large table >(10000000+ rows): Unfortunately PGSQL does not use indexes for min & max. One approach that should work is: select col1 from TABLE_A WHERE COL2 = 1 order by col2, col1 desc limit 1; and you will need an index on (col2, col1). ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.B.N. 75 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/