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

select union with table name

From: Akbar <akbarhome(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: select union with table name
Date: 2006-12-28 12:09:33
Message-ID: 5e8843f90612280409t7cd2695eg65a1ddf6d7b552fd@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-general
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?

Responses

pgsql-general by date

Next:From: Joris DobbelsteenDate: 2006-12-28 12:41:44
Subject: Re: select union with table name
Previous:From: AkbarDate: 2006-12-28 12:01:08
Subject: unique constraint on more than one tables

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