Search Postgresql Archives

Re: Select Query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxx

Get Sheeky @ http://Sheeky.Biz


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux