Re: Couple simple(?) questions...

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dmitri Touretsky <dmitri(at)listsoft(dot)ru>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Couple simple(?) questions...
Date: 2000-11-26 04:09:22
Message-ID: 28029.975211762@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Dmitri Touretsky <dmitri(at)listsoft(dot)ru> writes:
> 2. There is a table of the following structure:
> CREATE TABLE test (
> id int4,
> string1 text,
> string2 text,
> ord int2);

> I need to get a list of different "string1" strings ordered by
> "ord". But SELECT DISTINCT id, string1 ... ORDER BY ord" doesn't
> work. Is there any way to get it?

That doesn't seem very well defined. Your SELECT DISTINCT implies
that there may be multiple entries with the same string1 value, but
perhaps different ord values. Which ord value are you expecting that
string1 value to be sorted by?

Most likely you'll find that you need to do the SELECT DISTINCT into
a temp table, and then SELECT from the temp table with the desired
output ordering. In 7.1 it'll be possible to do this in a single
query using subselect-in-FROM, but in 7.0 that feature isn't there.

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Alain Toussaint 2000-11-26 05:07:46 Re: Re: [NOVICE] Re: re : PHP and persistent connections
Previous Message GH 2000-11-26 03:37:33 Re: Couple simple(?) questions...