Re: select union with table name - Mailing list pgsql-general

From Reece Hart
Subject Re: select union with table name
Date
Msg-id 1167368629.26596.3.camel@snafu.site
Whole thread Raw
In response to select union with table name  (Akbar <akbarhome@gmail.com>)
Responses Re: select union with table name  (Alban Hertroys <alban@magproductions.nl>)
List pgsql-general
On Thu, 2006-12-28 at 19:09 +0700, Akbar wrote:
> select blue.name from blue union select red.name from red
>  give me this:
> name
> 'blabla'
> 'bubu'
> 'haha'
> 'kkk'
>
> I want this:
> name    table_name
> 'blabla'   blue
> 'bubu'    blue
> 'haha'    red
> 'kkk'      red
>
> Could I?

select name,'blue' as "table_name" from blue union all select name,'red'
as "table_name" from red;

Note the 'all' after union... I suspect you'll want that or should at
least consider it.

-Reece

--
Reece Hart, http://harts.net/reece/, GPG:0x25EC91A0
./universe -G 6.672e-11 -e 1.602e-19 -protonmass 1.673e-27 -uspres bush
kernel warning: universe consuming too many resources. Killing.
universe killed due to catastrophic leadership. Try -uspres carter.


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: questions about migrating form postgres 7 to 8
Next
From: Ben
Date:
Subject: Re: Geographical redundancy