Re: select union with table name

Поиск
Список
Период
Сортировка
От Joris Dobbelsteen
Тема Re: select union with table name
Дата
Msg-id 73427AD314CC364C8DF0FFF9C4D693FF549C@nehemiah.joris2k.local
обсуждение исходный текст
Ответ на select union with table name  (Akbar <akbarhome@gmail.com>)
Список pgsql-general
Try:
select blue.name, 'blue' from blue union select red.name, 'red' from
red;

Not tested, but that should work.
One thing to remember:
If blabla is in both blue and red, it will appear twice, instead of only
once as in your example.

- Joris

>-----Original Message-----
>From: pgsql-general-owner@postgresql.org
>[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Akbar
>Sent: donderdag 28 december 2006 13:10
>To: pgsql-general@postgresql.org
>Subject: [GENERAL] select union with table name
>
>Hi, I have two tables.
>create table blue (
>  id serial primary key,
>  name text not null,
>  kill text not null
>);
>
>create table red (
>  id serial primary key,
>  name text not null,
>  kiss text not null
>);
>
>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?
>
>---------------------------(end of
>broadcast)---------------------------
>TIP 3: Have you checked our extensive FAQ?
>
>               http://www.postgresql.org/docs/faq
>

В списке pgsql-general по дате отправления:

Предыдущее
От: Akbar
Дата:
Сообщение: select union with table name
Следующее
От: Richard Broersma Jr
Дата:
Сообщение: Re: select union with table name