pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stijn Vanroye <s.vanroye@farcourier.com>
To: pgsql-sql@postgresql.org
Subject: select distinct and order by
Date: Wed, 28 Apr 2004 11:27:06 +0200
Message-ID: <71E201BE5E881C46811BA160694C5FCB046730@fs1000.farcourier.com> (raw)

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 
  (select staff_id from staffmembership where staffgroup_id=#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

-=[Today I got more responsabilities from my boss, as from now I'm responsible for everything that goes wrong ...]=-



view thread (8+ messages)  latest in thread

Message-ID: <71E201BE5E881C46811BA160694C5FCB046730@fs1000.farcourier.com>
Permalink:  ../71E201BE5E881C46811BA160694C5FCB046730@fs1000.farcourier.com/
Also on:    postgresql.org/message-id/71E201BE5E881C46811BA160694C5FCB046730@fs1000.farcourier.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: s.vanroye@farcourier.com
  Subject: Re: select distinct and order by
  In-Reply-To: <71E201BE5E881C46811BA160694C5FCB046730@fs1000.farcourier.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox