Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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

pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group