Re: searching multiple tables and databases

From: "Richard Teviotdale" <richard(at)satcomresources(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Re: searching multiple tables and databases
Date: 2001-11-08 19:41:39
Message-ID: 006201c1688d$65855980$0100007f@satcomresources.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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...

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Evelio Martínez 2001-11-08 19:52:45 How to optimize a column type change???
Previous Message Evelio Martínez 2001-11-08 19:18:18 How to migrate BLOBS between DB with less steps???