Обсуждение: searching multiple tables and databases

Поиск
Список
Период
Сортировка

searching multiple tables and databases

От
"mike sears"
Дата:
I'm currently looking for the best way to search across multiple tables and databases. I'm not sure where to even start and what would be the best way to approach this. if someone could point me in the right direction it would be greatly appreciated.
 
Mike

Re: searching multiple tables and databases

От
"Richard Teviotdale"
Дата:
 
>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...