I have first database (dbA) with table like this, named Username :
+------------------+--------------+
| Username | PhoneNumber |
+------------------+--------------+
| jamesbond007 | 555-0074 |
| batmanbegins | 555-0392 |
+------------------+--------------+
then, on the other side, I have dbB with table like this, named PrivateMessage :
+------------------+---------------------------------+
| Username | Message |
+------------------+---------------------------------+
| jamesbond007 | I need new bond-girl |
| batmanbegins | thanks for the paycheck, Nolan |
+------------------+---------------------------------+
now, how to combine this two tables from 2 different databases so the output will look like this :
+------------------+--------------+---------------------------------+
| Username | PhoneNumber | Message |
+------------------+--------------+---------------------------------+
| jamesbond007 | 555-0074 | I need new bond-girl |
| batmanbegins | 555-0392 | thanks for the paycheck, Nolan |
+------------------+--------------+---------------------------------+
You can simply join the table of different database. You need to specify the database name in your
FROMclause. To make it shorter, add anALIASon it,but some how, there are possiblities where-in a
usernamewon’t have messages. In this case useLEFT JOINif you want still to show all the records ofdba.Username.Reading from your comments, the tables have different
collation. The work around on this is to specifyCOLLATEon your joined statements,you can change
latin1_swedish_cito whatever you want.For more info on COLLATION, see this full list of
Character Sets and Collations in MySQL
If you have enough privilege to
ALTERthe tables, simply use this syntax to manually convert and match their collations,