php sql join together multiple tables from different databases

后端 未结 1 689
挽巷
挽巷 2020-12-18 12:24

I have 3 databases, and now I need to join several tables from each one of them into a singel query. How do I do this?

This is my connection:

<
相关标签:
1条回答
  • 2020-12-18 12:58

    You will need a user that has access to all three databases.

    You will JOIN them together by specifying full table name, something like this:

    SELECT * FROM database_1.logs AS d1 LEFT JOIN database_2.users AS d2 
      ON d1.username = d2.username ORDER BY d1.timestamp DESC LIMIT 10
    
    0 讨论(0)
提交回复
热议问题