If the databases are on the same instance (server) then all you need to do is fully qualify the table names. For example ...
FROM [DatabaseA].[TableOwnerA].TableA AliasA INNER JOIN [DatabaseB].[TableOwnerB].[TableB] AliasB ON ...
Strictly speaking you don't need the full qualification on the database to which you are connected but the way I've shown it means you can connect to either database and get the same result.
If the databases are on different SQL instances then you will need to set each server up as a "Linked Server" to the other.
Microsoft documentation on setting up a linked server[
^]