pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
DISTINCT ON () with UNION
2+ messages / 2 participants
[nested] [flat]

* DISTINCT ON () with UNION
@ 2001-05-13 23:14  pgsql@peope.net
  0 siblings, 1 reply; 2+ messages in thread

From: pgsql@peope.net @ 2001-05-13 23:14 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: DISTINCT ON () with UNION
@ 2001-05-14 00:52  Tom Lane <tgl@sss.pgh.pa.us>
  parent: pgsql@peope.net
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2001-05-14 00:52 UTC (permalink / raw)
  To: pgsql@peope.net; +Cc: pgsql-sql

pgsql@peope.net writes:
> How can you use a distinct on () including the whole union.

In 7.1 you can write

select distinct ... from (select ... union select ...) ss;

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2001-05-14 00:52 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-05-13 23:14 DISTINCT ON () with UNION pgsql@peope.net
2001-05-14 00:52 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox