only works if both databases are on the same mysql-server, joins over different mysql-servers are not possible
Main Topics
Browse All TopicsHello, I have a question about Inner Join MySQL statement. I'd like to create inner join sql statement with 2 tables. Each table belong to different databases. How can i code to get connection and make sql statement?? If you show give some advices and some sample codes, I appreciate it.
BestWish, portal123
my code:
require_once('../dbini.php
$con=mysql_connect($DBSERV
$db_select=mysql_select_db
$sql="SELECT * FROM tbl_a WHERE SHOP_ID=8";
$res=mysql_query($sql);
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
hi!, I made up the inner join SQL statement. Both MYSQL databases are on the same my sql-server. But mysql_query does not work and return error message(:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource).
//for connection to database1 and table name is tbl_product1
require_once('../dbini.php
$con=mysql_connect($DBSERV
$db_select=mysql_select_db
//for connection to database2 and table name is tbl_product2
require_once('admin_dbini.
$con1=mysql_connect($DBSER
$db_select1=mysql_select_d
$sql= "SELECT db2.m_msg.comment FROM db2.m_msg INNER JOIN db1.tbl_product ON db2.tbl_product2.PID=db1.t
if($res=mysql_query($sql))
print "YES";
}else{
print "NO";
}
Business Accounts
Answer for Membership
by: hernst42Posted on 2005-09-29 at 06:43:28ID: 14983533
Have you tries to use
databasename.table name to select the table fro ma different databse? e.g.
$sql="SELECT * FROM $DBNAME.tbl_a, $DBNAME2.tbl_b WHERE SHOP_ID=8";