From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
---|---|
To: | Nicolas <bnk(at)medialife(dot)net> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Distinct Values |
Date: | 2001-06-05 21:14:19 |
Message-ID: | Pine.BSF.4.21.0106051411290.10996-100000@megazone23.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Wed, 30 May 2001, Nicolas wrote:
> Hi,
>
> I'm trying to retreive DISTINCT Values from a two colomn table called
> "Books". The colomns are named "Author" and "URL".
> DISTINCT values should be retieved from the "Author" Colomn , and then I
> should be able to retrieve the corresponding URL.
> How do I build the SQL Query ?
> I tried to use: "SELECT DISTINCT Author FROM Books" But this does not allow
> me to fetch the URL value on the other colomn.
If there is only one distinct url for each author then:
select distinct author, url from books;
If not, *which* url do you want to get?
If it doesn't matter, you can use a non-standard structure:
select distinct on (author) author, url;
If you wanted (for example) the url that could be considered
the minimum, you could do something like:
select author, min(url) from books group by author;
From | Date | Subject | |
---|---|---|---|
Next Message | Stephan Szabo | 2001-06-05 21:30:38 | Re: query on two databases .. |
Previous Message | Chris Ruprecht | 2001-06-05 19:17:02 | Re: [PHP] PHP-PostgreSQL - install |