Re: help with a view (join-query)

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: me(at)alternize(dot)com
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: help with a view (join-query)
Date: 2006-03-25 23:59:11
Message-ID: 20060325235911.GA6265@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, Mar 24, 2006 at 19:36:34 +0100,
me(at)alternize(dot)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 person is listed exactly once, and to each person only one (of possible more) events is listed. it does not matter which ones of the events are shown. when doing a normal JOIN, the resultset might return more than one record per person (for each event one line).
> is there an easy way to build a query that fullfills my needs? i'd rather not check programmatically if i already listed the 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.

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message me 2006-03-26 03:12:56 Re: help with a view (join-query)
Previous Message John DeSoi 2006-03-25 13:47:28 Re: Bytea and perl