Re: select union with table name

Поиск
Список
Период
Сортировка
От Reece Hart
Тема Re: select union with table name
Дата
Msg-id 1167368629.26596.3.camel@snafu.site
обсуждение исходный текст
Ответ на select union with table name  (Akbar <akbarhome@gmail.com>)
Ответы Re: select union with table name  (Alban Hertroys <alban@magproductions.nl>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: questions about migrating form postgres 7 to 8
Следующее
От: Ben
Дата:
Сообщение: Re: Geographical redundancy