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 10D9CD1CE3E for ; Mon, 2 Feb 2004 23:07:08 +0000 (GMT) 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 36170-08 for ; Mon, 2 Feb 2004 19:07:07 -0400 (AST) Received: from skycasters.net (mail.skycasters.net [204.232.30.5]) by svr1.postgresql.org (Postfix) with ESMTP id AAA76D1C513 for ; Mon, 2 Feb 2004 19:07:04 -0400 (AST) Received: from think.esc1.com [66.82.143.102] by skycasters.net with ESMTP (SMTPD32-8.05) id A815BCEE0130; Mon, 02 Feb 2004 18:07:01 -0500 Received: from localhost (localhost [[UNIX: localhost]]) by think.esc1.com (8.11.6/8.11.6) id i12N0X913622 for pgsql-sql@postgresql.org; Mon, 2 Feb 2004 18:00:33 -0500 Content-Type: text/plain; charset="iso-8859-1" From: Terry Lee Tucker Organization: Enhanced Solutions Computing To: pgsql-sql@postgresql.org Subject: Re: Novice SQL Question Date: Mon, 2 Feb 2004 18:00:32 -0500 User-Agent: KMail/1.4.1 References: <200402021738.06828.terry@esc1.com> In-Reply-To: <200402021738.06828.terry@esc1.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200402021800.32906.terry@esc1.com> X-Declude-Sender: terry@esc1.com [UNIX: localhost] X-Declude-Spoolname: Dd815bcee0130fa78.SMD X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/24 X-Sequence-Number: 16715 To answer my own question: I discoverd that the order by fields had to be in the select list. Apparent= ly,=20 this is a requirement when using "DISTINCT". On Monday 02 February 2004 05:38 pm, Terry Lee Tucker wrote: > I need to the following query: > select distinct event_code, level from logs join stat on (stat.prime is n= ot > null) where order_num =3D 130680; > > Ok, no problem. Does exactly what I want; however, I need to sort this is= a > particular way to get the right results. When I try to add the order by > clause, I get an error. Here is the ORDER BY: > ORDER BY event_date DESC, event_time DESC, event_secs DESC > > If I put this where I thought it should go as in: > select distinct event_code,level from logs join stat on (stat.prime is not > null) where order_num =3D 130680 order by event_date,event_time,event_sec= s; > > I get the following error: > ERROR: For SELECT DISTINCT, ORDER BY expressions must appear in target > list > > No matter where I put it I get errors. Obviously, I'm a novice. Can > somebody give me any advice? I'm using Postgres 7.2.3 on RedHat. > > Thanks... --=20 Quote: 48 "Exceeding the bounds of authority is no more a right in a great than in a petty officer, no more justifiable in a king than in a constable; but is so much the worse in him, in that he has more trust put in him, has already a much greater share than the rest of his brethren, and is supposed from the advantages of his education, employment, and coun- sellors, to be more knowing in the measures of right and wrong." --John Locke Work: 1-336-372-6812 Cell: 1-336-363-4719 email: terry@esc1.com