Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f4DNR9A49306 for ; Sun, 13 May 2001 19:27:09 -0400 (EDT) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.1/8.11.1) id f4DNCXC26550 for pgsql-sql@postgresql.org; Sun, 13 May 2001 19:12:33 -0400 (EDT) (envelope-from news) From: pgsql@peope.net X-Newsgroups: comp.databases.postgresql.sql Subject: DISTINCT ON () with UNION Date: Sun, 13 May 2001 23:14:04 GMT Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 37 Message-ID: <20010513.23140422@mis.configured.host> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Complaints-To: scrappy@hub.org X-Priority: 3 (Normal) X-Newsreader: Mozilla/3.0 (compatible; StarOffice/5.2;Win32) To: pgsql-sql@postgresql.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by postgresql.org id f4DNRAA49323 X-Archive-Number: 200105/119 X-Sequence-Number: 2935 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