Re: Select Query - Mailing list pgsql-general

From Shane Ambler
Subject Re: Select Query
Date
Msg-id 45A73332.9060409@007Marketing.com
Whole thread Raw
In response to Select Query  (Ashish Karalkar <ashish_karalkar@yahoo.com>)
List 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@007Marketing.com

Get Sheeky @ http://Sheeky.Biz

pgsql-general by date:

Previous
From: Ashish Karalkar
Date:
Subject: Select Query
Next
From: Artis Caune
Date:
Subject: plpgsql and arrays