RE: [PHP-DB] How to querry two db in a single statement?
| From: | Jonathan Hilgeman | Date: | Fri, 04 Jan 2002 16:09:12 +0000 |
| Subject: | RE: [PHP-DB] How to querry two db in a single statement? | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-15395@lists.php.net to get a copy of this message | ||
If the two databases are on the same server, you can use joins to select
data from multiple databases.
For instance:
Database 1, Table A:
--------------------
| id | name |
--------------------
| 1 | George |
| 2 | Mark |
| 3 | Harry |
--------------------
Database 2, Table A:
--------------------
| id | name |
--------------------
| 1 | Bill |
| 2 | Henry |
| 3 | Ford |
--------------------
You can:
SELECT a.name as db1Name, b.name as db2Name FROM Database1.TableA a LEFT
JOIN Database2.TableA b ON a.id=b.id;
Now you'll get:
-----------------------
| db1Name | db2Name |
-----------------------
| George | Bill |
| Mark | Henry |
| Harry | Ford |
-----------------------
Hope this helps.
- Jonathan
-----Original Message-----
From: Andy [mailto:news.letters@gmx.de]
Sent: Friday, January 04, 2002 5:50 AM
To: php-db@lists.php.net
Subject: [PHP-DB] How to querry two db in a single statement?
Hi there,
I would like to make a querry on 2 db. There is info in tables I would like
to compare.
As I know, there has first to be a conect on the db before the querry. But
how to do this on 2 db??
Thanx for any help.
Andy
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
For additional commands, e-mail: php-db-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net