Re: searching multiple tables and databases - Mailing list pgsql-general

From Richard Teviotdale
Subject Re: searching multiple tables and databases
Date
Msg-id 006201c1688d$65855980$0100007f@satcomresources.com
Whole thread Raw
In response to searching multiple tables and databases  ("mike sears" <matrix@quadrent.net>)
List pgsql-general
 
>I'm currently looking for the best way to search across multiple tables and databases.
 
You use a union query to join the results from multiple queries from different tables. For example:
 
Employees Table
1    Peter
2    Paul
3    Mary
 
Customers Table
1    John
2    Ringo
3    Paul
 
SELECT 'Employee' AS what, id, name
FROM Employees
WHERE name ~* '^P'
UNION
SELECT 'Customer' AS what, id, name
FROM Customers
WHERE name ~* '^P'
ORDER BY name;
 
Would return something like:
Employee    2    Paul
Customer    3    Paul
Employee    1    Peter
 
I can't tell you how you would do something like this accross multiple databases. There may be better ways...
 

pgsql-general by date:

Previous
From: Einar Karttunen
Date:
Subject: Re: problem connecting client to a postgresSQL server
Next
From: mirko@picard.inka.de (Mirko Zeibig)
Date:
Subject: Re: Why is there no option -U with pg_dump?