Re: Question About UNION

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Bill Thoen <bthoen(at)gisnet(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Question About UNION
Date: 2008-10-09 17:06:48
Message-ID: 48EE3A28.8040505@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 09/10/2008 17:59, Bill Thoen wrote:
>>> I'm trying to combine two tables, but I only want unique records based
>>> on the first two columns. Can UNION be used to join three-column tables
>>> but only include records based on the uniqueness of the first two
>>> columns? If not, how would I do this with PostgreSQL 8.1?
>>>
>>
>> How do you decide which records you want? - e.g. given the following
>> rows...
>>
>> (a, b, c)
>> (a, b, d)
>>
>> ...how do you decide whether you the one with c or the one with d?
>>
>>
> The physical order that they appear will take care of that.

Hmmmm....

Leaving that aside, how about SELECTing the columns you want to be
unique from the two tables, and then JOINing the UNION of those back
with the UNION of the complete (three-column) tables?

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod(at)iol(dot)ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bill Thoen 2008-10-09 17:19:56 Re: Question About UNION
Previous Message Bill Thoen 2008-10-09 16:59:39 Re: Question About UNION