Choice from two bases for one request



  • Good afternoon. Wanted to know if it was possible to select information from different databases for one request?



  • If the request indicates the table in the name of the database database1.table1the table is selected from database1if it's just table1- from the active database.

    General principle of cross-request for two bases within one MySQL server:

    SELECT t1.*, t2.*
    FROM database1.table1 AS t1
    INNER JOIN database2.table2 AS t2 ON t2.field1 = t2.field1
    

    Alias t1 and t2 Not necessarily. But they reduce the demand, and improve the readability.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2