Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by postgresql.org (8.11.3/8.11.4) with SMTP id fA8JCMm13914 for ; Thu, 8 Nov 2001 14:12:22 -0500 (EST) (envelope-from cniesen@gmx.net) Received: (qmail 12907 invoked by uid 0); 8 Nov 2001 19:12:21 -0000 Received: from pc79088.adp.iastate.edu (HELO D8VGHK.gmx.net) (129.186.79.88) by mail.gmx.net (mp007-rz3) with SMTP; 8 Nov 2001 19:12:21 -0000 Message-Id: <5.1.0.14.2.20011108093538.00ae2858@pop.gmx.net> X-Sender: 196541@pop.gmx.net X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Thu, 08 Nov 2001 13:11:34 -0600 To: pgsql-sql@postgresql.org From: Claus Heiko Niesen Subject: Re: Can this query be optimized? In-Reply-To: <16760.1005229805@sss.pgh.pa.us> References: <5.1.0.14.2.20011107144418.00a83b68@pop.gmx.net> <5.1.0.14.2.20011107144418.00a83b68@pop.gmx.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200111/134 X-Sequence-Number: 5518 Ooops, I posted one test SQL statements which really didn't make sense. This is the correct one: select distinct extract(year from date) as year, extract(month from date) as month from week_pics order by year desc, month desc; I try to get a list of all the months that have a picture. So the day part of the date should be ignored. Claus At 08:30 AM 11/08/2001, Tom wrote: >Claus Heiko Niesen writes: > > I'm stuck optimizing the following query: > > select distinct extract(year from date) as year, extract(month from date) > > as month, date from week_pics order by date desc; > >Perhaps it would work to forget the "distinct" and instead GROUP BY >date. > > regards, tom lane