X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 9D675D1BABA for ; Thu, 22 Apr 2004 10:37:10 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 55858-04 for ; Thu, 22 Apr 2004 10:37:11 -0300 (ADT) Received: from web12704.mail.yahoo.com (web12704.mail.yahoo.com [216.136.173.241]) by svr1.postgresql.org (Postfix) with SMTP id 64927D1B560 for ; Thu, 22 Apr 2004 10:37:07 -0300 (ADT) Message-ID: <20040422133709.27730.qmail@web12704.mail.yahoo.com> Received: from [194.152.216.133] by web12704.mail.yahoo.com via HTTP; Thu, 22 Apr 2004 06:37:09 PDT Date: Thu, 22 Apr 2004 06:37:09 -0700 (PDT) From: Subject: Re: Order by YYYY MM DD in reverse chrono order trouble To: pgsql-sql@postgresql.org In-Reply-To: <25337.1082638880@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=3.8 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME, RCVD_IN_DSBL, RCVD_IN_NJABL, RCVD_IN_NJABL_PROXY, RCVD_IN_SORBS, RCVD_IN_SORBS_HTTP X-Spam-Level: *** X-Archive-Number: 200404/230 X-Sequence-Number: 17605 Hello, Hm, doesn't work for me: me@[local] mydb=> select distinct date_part('year', uu.add_date), date_part('month', uu.add_date), date_part('day', uu.add_date) from uus inner join ui on uus.user_id=ui.id inner join uu on ui.id=uu.user_id where uus.subscriber_user_id=1 order by uu.add_date desc; ERROR: For SELECT DISTINCT, ORDER BY expressions must appear in target list I have this version of PostgreSQL installed: postgresql-7.3.4-3.rhl9 Thanks, Otis --- Tom Lane wrote: > writes: > > I'd love to be able to do that, but I cannot just ORDER BY > uu.add_date, > > because I do not have uu.add_date in the SELECT part of the > statement. > > Sure you can. Back around SQL89 there was a restriction that ORDER > BY > values had to appear in the SELECT list as well, but no modern > database > has such a restriction anymore ... > > regards, tom lane