List:General Discussion« Previous MessageNext Message »
From:Thimble Smith Date:May 7 1999 1:25am
Subject:Re: join across databases?
View as plain text  
On Wed, May 05, 1999 at 11:55:50PM -0700, Chuck wrote:
> Consider, mysql_connect returns a $link reference.  Since 'mysql_query_db'
> (the modern version of 'mysql') takes only one $link reference, joins
> across multiple servers would not be possible, and probably a violation of
> the definition of 'join'.

That isn't correct.  It's true that you can only be "connected" to
one database at a time.  But really your connection is to the database
server; the database name is just a default name - but querying over
two or three databases at once is not different from querying just one
database.  You just have to specify the database names instead of
relying on the default.

Here's an example:

mysql> select * from test.foo;
+------+
| num  |
+------+
|    0 |
+------+
1 row in set (0.02 sec)

mysql> select * from tim.udf_groups;
+----+---------+---------+----------+-------+
| id | type    | type_id | position | count |
+----+---------+---------+----------+-------+
|  1 | column  |       1 |        1 |     2 |
|  2 | section |       1 |        1 |     1 |
|  3 | global  |       0 |        1 |     1 |
+----+---------+---------+----------+-------+
3 rows in set (0.02 sec)

mysql> select * from tim.udf_groups left join test.foo on (type_id = num);
+----+---------+---------+----------+-------+------+
| id | type    | type_id | position | count | num  |
+----+---------+---------+----------+-------+------+
|  1 | column  |       1 |        1 |     2 | NULL |
|  2 | section |       1 |        1 |     1 | NULL |
|  3 | global  |       0 |        1 |     1 |    0 |
+----+---------+---------+----------+-------+------+
3 rows in set (0.02 sec)

mysql> 

Dävid, if you're still not getting the syntax, why don't you give us
a real example that you'd like to do, and we'll give you the syntax.

Tim
Thread
join across databases?Daevid Vincent6 May
  • Re: join across databases?Thimble Smith6 May
  • Re: join across databases?Daevid Vincent6 May
    • Re: join across databases?Thimble Smith6 May
  • Re: join across databases?Daevid Vincent6 May
    • Re: join across databases?Chuck6 May
      • Re: join across databases?Thimble Smith7 May
  • Re: join across databases?kalle volkov6 May