Tell me, please, how to do it correctly?

There is a data1 database with the wp_users and the user_login string.
There is a data2 database with a money table and the string username and balance .
The user_login and username fields, though in different tables, are the same.

How to make a sample so that user_login chooses username and see what value in the line balance and output it to a variable? There are sketches that do not work.

  • And that means user_login chose username. What are the sampling conditions from the first table? In general, select balance from data1.wp_users a, data2.money b where a.user_login = b.username. But you probably want something else - Mike

1 answer 1

You can use the following query

 SELECT u.user_login AS user, m.balance AS balance FROM data1.wp_users AS u LEFT JOIN data2.money AS m ON u.user_login = m.username