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 D2EEED1B8B1 for ; Wed, 28 Apr 2004 06:27:23 -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 68046-03 for ; Wed, 28 Apr 2004 06:27:24 -0300 (ADT) Received: from mail.cobweb.nl (mx1.cobweb.nl [80.242.96.4]) by svr1.postgresql.org (Postfix) with ESMTP id 0266ED1B8FE for ; Wed, 28 Apr 2004 06:27:21 -0300 (ADT) Received: from farcourier.com (dp3-26.dsl.cobweb.nl [193.67.120.154] (may be forged)) by mail.cobweb.nl (8.12.8/8.12.7) with ESMTP id i3S9RRvF066432 for ; Wed, 28 Apr 2004 11:27:28 +0200 (CEST) (envelope-from s.vanroye@farcourier.com) MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: select distinct and order by X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 content-class: urn:content-classes:message Date: Wed, 28 Apr 2004 11:27:06 +0200 Message-ID: <71E201BE5E881C46811BA160694C5FCB046730@fs1000.farcourier.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] select distinct and order by Thread-Index: AcQtAvke5FKMtco5SaKHVI/FUsTzXg== From: "Stijn Vanroye" To: X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200404/311 X-Sequence-Number: 17686 Hello everybody, I have a short question: I'm trying to run the following query: select distinct on (staff_id) staff_id, fullname, loginname from staff where staff_id in=20 (select staff_id from staffmembership where staffgroup_id=3D#SomeIdValue#) order by fullname I get the follwing error: select distinct on expressions must match the initial order by expression Does this mean that I can only order by the same fields as the ones that I = use in the distinct? If so, is there still a way that I can select distinct on the keyfield, and= still sort by the name. However unlikely, it could happen that two people = have the same name, so a distinct on fullname could make problems. The facts: - PostgreSQL 7.3.2 running on RH 9 - pgODBC 7.3.0200 - Borland Delphi 7 enterprise Regards, Stijn Vanroye -=3D[Today I got more responsabilities from my boss, as from now I'm respon= sible for everything that goes wrong ...]=3D-