MySQL adds the current db as a prefix automatically

Say I have two databases, db1 and db2, and I have full privileges to access them.
But when I output 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.tbl1exists. Mysql seems to automatically add the database name as a prefix. What am I doing wrong?

+4
source share
2 answers

You should pay attention to the database name and table name separately:

SELECT * FROM `db1`.`tbl1` AS t1 JOIN `db2`.`tbl2` AS t2 ON t1.id=t2.id

Or simply without backlinks if there is no stock name.

SELECT * FROM db1.tbl1 AS t1 JOIN db2.tbl2 AS t2 ON t1.id=t2.id
+4
source

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 `till with the name and the name of the database.

0
source

All Articles