Re: Couple simple(?) questions... - Mailing list pgsql-novice

From Tom Lane
Subject Re: Couple simple(?) questions...
Date
Msg-id 28029.975211762@sss.pgh.pa.us
Whole thread Raw
In response to Couple simple(?) questions...  (Dmitri Touretsky <dmitri@listsoft.ru>)
List pgsql-novice
Dmitri Touretsky <dmitri@listsoft.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

pgsql-novice by date:

Previous
From: GH
Date:
Subject: Re: Couple simple(?) questions...
Next
From: "Mitch Vincent"
Date:
Subject: Re: [HACKERS] Re: Re: re : PHP and persistent connections