Re: [PHP-DB] join across databases - how to select databases?
to my knowledge this is not possible in MySQL. There are only joins at the table level. I've been curious about this in the past myself, so if i'm incorrect, i'm hoping to hear it via this post. hth jeff Moshe Weitzman [EMAIL PROTECTED]To: [EMAIL PROTECTED] ourmet.org cc: Subject: [PHP-DB] join across databases - how to select databases? 08/22/2003 11:16 AM I have looked all over the web but can't find an example *in php* for connecting to a mysql server, selecting database(s), and issueing a query which joins across databases. I already know the SQL required to achieve a multiple database query. My question is about how many calls to mysql_select_db() are required, does order matter, etc. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] join across databases - how to select databases?
From: Moshe Weitzman [EMAIL PROTECTED] I have looked all over the web but can't find an example *in php* for connecting to a mysql server, selecting database(s), and issueing a query which joins across databases. I already know the SQL required to achieve a multiple database query. My question is about how many calls to mysql_select_db() are required, does order matter, etc. What have you tried? What does mysql_error() say after each attempt? I assume something like the following would work, regardless of whether/how you've called mysql_select_db() SELECT t1.column FROM database1.table1 t1 JOIN database2.table2 t2 ON t1.id = t2.id If you have something working from the MySQL command line, then it's going to work from mysql_query() with the same exact syntax. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] join across databases - how to select databases?
From: [EMAIL PROTECTED] to my knowledge this is not possible in MySQL. There are only joins at the table level. I've been curious about this in the past myself, so if i'm incorrect, i'm hoping to hear it via this post. You can stop hoping now. It is indeed possible. :) mysql select * from test1.table1; ++--+ | id | name | ++--+ | 1 | John | | 2 | Bill | | 3 | Mark | ++--+ 3 rows in set (0.00 sec) mysql select * from test2.table2; ++-+ | id | name| ++-+ | 1 | Holmes | | 2 | Foreman | | 3 | Smith | ++-+ 3 rows in set (0.00 sec) mysql select t1.name, t2.name from test1.table1 t1 join test2.table2 t2 on t1.id = t2.id; +--+-+ | name | name| +--+-+ | John | Holmes | | Bill | Foreman | | Mark | Smith | +--+-+ 3 rows in set (0.00 sec) ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] join across databases - how to select databases?
I assume something like the following would work, regardless of whether/how you've called mysql_select_db() SELECT t1.column FROM database1.table1 t1 JOIN database2.table2 t2 ON t1.id = t2.id If you have something working from the MySQL command line, then it's going to work from mysql_query() with the same exact syntax. You are indeed correct. I had a bug in my join syntax. How embarrassing. For the record, you don't even have to call mysql_select_db() at all. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php