Search code examples
mysqlsqlidentifier

selecting database name, table name and column name.


The MySql manual states:

*Similarly, to retrieve from a table 't' in database 'db1' and from a table 't' in database 'db2' in the same statement, you must refer to columns in those tables as 'db1.t.col_name' and 'db2.t.col_name'.*

How would one go about creating such a select statement?


Solution

  • Use different alias names for the tables that have the same name but are in different DBs

    select d1.col1, d2.col1
    from db1.table1 d1
    inner join db2.table1 d2 on d1.id = d2.id