Re: Distinct Values - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: Distinct Values
Date
Msg-id Pine.BSF.4.21.0106051411290.10996-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Distinct Values  ("Nicolas" <bnk@medialife.net>)
List 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;





pgsql-sql by date:

Previous
From: Nils Zonneveld
Date:
Subject: Re: query on two databases ..
Next
From: "Chris Ruprecht"
Date:
Subject: Re: [PHP] PHP-PostgreSQL - install