DISTINCT ON () with UNION

From: Per-Olof Pettersson <pgsql(at)peope(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: DISTINCT ON () with UNION
Date: 2001-05-13 23:20:14
Message-ID: 20010513.23201496@mis.configured.host
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

How can you use a distinct on () including the whole union.

eg

select distinct on (valutaid) valutaid, short from valuta UNION select
landid, land from land order by valutaid;

table: valuta
valutaid valuta
1 USD
2 SEK

table: land
landid land
1 Sweden
2 USA
3 Norway

The above would give
1 USD
1 Sweden
2 SEK
2 USA
3 Norway

What I would like to get is
1 USD
2 SEK
3 Norway

I did specify distinct on (valutaid) anyways =)

Any suggestions?

Best regards
Per-Olof Pettersson

Browse pgsql-general by date

  From Date Subject
Next Message Eric G. Miller 2001-05-13 23:49:29 Re: Bug with timestamp !!!
Previous Message Howard Williams 2001-05-13 21:57:38 trigger/function question