FW: select union with table name

From: "antsumees" <antsumees(at)hot(dot)ee>
To: <pgsql-general(at)postgresql(dot)org>
Subject: FW: select union with table name
Date: 2006-12-28 13:39:10
Message-ID: 20061228134101.EE7DCE1171@Relayhost2.neti.ee
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Try this

Select name, 'blue' as table_name from blue
Union all
Select name, 'red' as table_name from red

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Akbar
Sent: Thursday, December 28, 2006 2:10 PM
To: pgsql-general(at)postgresql(dot)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

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-12-28 15:17:59 Re: Improve response time of a SQL command
Previous Message Ron Johnson 2006-12-28 13:23:20 Re: Re: [GENERAL] ??: [GENERA