Thread: Select Query

Select Query

From
Ashish Karalkar
Date:
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??

With regards
Ashish Karalkar



____________________________________________________________________________________
Don't get soaked.  Take a quick peak at the forecast
with the Yahoo! Search weather shortcut.
http://tools.search.yahoo.com/shortcuts/#loc_weather

Re: Select Query

From
Shane Ambler
Date:
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