Re: Select Query

From: Shane Ambler <pgsql(at)007Marketing(dot)com>
To: Ashish Karalkar <ashish_karalkar(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Select Query
Date: 2007-01-12 07:05:22
Message-ID: 45A73332.9060409@007Marketing.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ashish Karalkar wrote:
> Hello List,
>
> I am having list of tables , what I want to do is to
> filter this list of table for a particular value of
> its column, the column which i will be searching is
> common accross all tables in list
>
> any clues??
>

Something like

SELECT * FROM
(
SELECT col1,col2 FROM table1
UNION
SELECT col1,col2 FROM table2
UNION
SELECT col1,col2 FROM table3
) AS at

WHERE at.col1=3

if the cols are different names you would change
SELECT col1,col2
to SELECT col3 as col1,col2

If you are looking for the table that has the value you will want
something like -

SELECT c.relname,* FROM (
SELECT tableoid,col1,col2 FROM table1
UNION
SELECT tableoid,col1,col2 FROM table2
UNION
SELECT tableoid,col1,col2 FROM table3
) as at

left join pg_class c on at.tableoid=c.oid

WHERE at.col1=3

--

Shane Ambler
pgSQL(at)007Marketing(dot)com

Get Sheeky @ http://Sheeky.Biz

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Artis Caune 2007-01-12 09:03:42 plpgsql and arrays
Previous Message Ashish Karalkar 2007-01-12 05:48:52 Select Query