Re: help with a view (join-query) - Mailing list pgsql-novice

From Bruno Wolff III
Subject Re: help with a view (join-query)
Date
Msg-id 20060325235911.GA6265@wolff.to
Whole thread Raw
In response to help with a view (join-query)  (<me@alternize.com>)
List pgsql-novice
On Fri, Mar 24, 2006 at 19:36:34 +0100,
  me@alternize.com wrote:
> hi list
>
> currently in our database, a "person" contains a relation to one or more "events". i now need a view where each
personis listed exactly once, and to each person only one (of possible more) events is listed. it does not matter which
onesof the events are shown. when doing a normal JOIN, the resultset might return more than one record per person (for
eachevent one line).  
> is there an easy way to build a query that fullfills my needs? i'd rather not check programmatically if i already
listedthe person or not. 

You could use the Postgres specific extension DISTINCT ON to do this. You can
even use ORDER BY to make which row you grab deterministic.

pgsql-novice by date:

Previous
From: John DeSoi
Date:
Subject: Re: Bytea and perl
Next
From:
Date:
Subject: Re: help with a view (join-query)