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 117A1D1B45B for ; Mon, 2 Feb 2004 22:45:32 +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 32218-04 for ; Mon, 2 Feb 2004 18:45:05 -0400 (AST) Received: from skycasters.net (mail.skycasters.net [204.232.30.5]) by svr1.postgresql.org (Postfix) with ESMTP id BC149D1B4D2 for ; Mon, 2 Feb 2004 18:45:01 -0400 (AST) Received: from think.esc1.com [66.82.143.102] by skycasters.net with ESMTP (SMTPD32-8.05) id A2D0D729011C; Mon, 02 Feb 2004 17:44:32 -0500 Received: from localhost (localhost [[UNIX: localhost]]) by think.esc1.com (8.11.6/8.11.6) id i12Mc7a13559 for pgsql-sql@postgresql.org; Mon, 2 Feb 2004 17:38:07 -0500 Content-Type: text/plain; charset="us-ascii" From: Terry Lee Tucker Organization: Enhanced Solutions Computing To: pgsql-sql@postgresql.org Subject: Novice SQL Question Date: Mon, 2 Feb 2004 17:38:06 -0500 User-Agent: KMail/1.4.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200402021738.06828.terry@esc1.com> X-Declude-Sender: terry@esc1.com [UNIX: localhost] X-Declude-Spoolname: Dd2d0d729011c6770.SMD X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/23 X-Sequence-Number: 16714 I need to the following query: select distinct event_code, level from logs join stat on (stat.prime is not= =20 null) where order_num =3D 130680; Ok, no problem. Does exactly what I want; however, I need to sort this is a= =20 particular way to get the right results. When I try to add the order by=20 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= =20 null) where order_num =3D 130680 order by event_date,event_time,event_secs; 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 somebod= y=20 give me any advice? I'm using Postgres 7.2.3 on RedHat. Thanks... --=20 Work: 1-336-372-6812 Cell: 1-336-363-4719 email: terry@esc1.com