I have 2 tables
table1 in database1 on server1 having userID and userName
table2 in database2 on server2 having 开发者_如何学编程 userID
I need a way to access table1 on server1 to get the userName of the userID in table2
How do I do query using MySQL?
I think you can use 2 different connections:
$connection1= mysql_connect('server1', 'user1', 'password1');
$connection2= mysql_connect('server2', 'user2', 'password2');
Retrieve data from database 1, and use it to query database2. Or the opposite, depending on what you need. This means you'll use 2 queries.
Edit: I automatically assumed you're using php, hence my answer. I'm sorry if it's irrelevant.
MySQL supports federated tables - tables housed in a physically distinct server instance. It makes the remote table appear local, and any queries executed on it are transparently sent to the remote server for execution.
not sure about mysql...
in Oracle you would link the databases and then fully qualify the table references in your query (with '.' seperators)
精彩评论