Reputation: 5999
Say I have two databases db1 and db2, and I have full privileges to access them.
But when I issue the following sql:
SELECT * FROM `db1.tbl1` AS t1 JOIN `db2.tbl2` AS t2 ON t1.id=t2.id
I get this error:
Table `db1.db1.tbl1` doesn't exist.
db1.tbl1
does exist. It seems mysql automatically add database name as prefix. What am I doing wrong?
Upvotes: 4
Views: 140
Reputation: 160833
You should backtick quote the database name and table name separately:
SELECT * FROM `db1`.`tbl1` AS t1 JOIN `db2`.`tbl2` AS t2 ON t1.id=t2.id
Or just without backticks if there is no reserve name.
SELECT * FROM db1.tbl1 AS t1 JOIN db2.tbl2 AS t2 ON t1.id=t2.id
Upvotes: 4
Reputation: 15603
You need to do this:
SELECT * FROM `db1`.`tbl1` AS t1 JOIN `db2`.`tbl2` AS t2 ON t1.id=t2.id;
You need to add the ` till with the both table name and database name.
Upvotes: 0