Skip site navigation (1) Skip section navigation (2)

Re: table unions

From: "Sean Davis" <sdavis2(at)mail(dot)nih(dot)gov>
To: "Wright, George" <George(dot)Wright(at)infimatic(dot)com>
Cc: pgsql <pgsql-novice(at)postgresql(dot)org>
Subject: Re: table unions
Date: 2008-08-08 15:49:58
Message-ID: 264855a00808080849h7f960d5cw3d1a1e57e5881377@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
On Fri, Aug 8, 2008 at 11:13 AM, Wright, George
<George(dot)Wright(at)infimatic(dot)com> wrote:
> Novice question:
>
> How can I apply conditional logic when doing a union of two tables?
>
> TableA                       TableB
> ------                      ------
> value1  value2               value1  value2
>   1      10                    5      15
>  11      20
>
> SELECT * FROM TableA UNION SELECT * FROM TableB;
> returns:
>
> value1  value2
>   1      10
>   5      15
>  11      20
>
>
> what I want is
>
> value1  value2
>   1       5
>   5      15
>  15      20
>
> The tables are huge and already in ascending order.

Hi, George.

What conditional logic are you trying to apply?  Union will simply
take the rows from the two tables and combine them.

Sean

In response to

Responses

pgsql-novice by date

Next:From: Wright, GeorgeDate: 2008-08-08 15:59:40
Subject: Re: table unions
Previous:From: Wright, GeorgeDate: 2008-08-08 15:13:34
Subject: table unions

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group