Query 3 DBs depending on column name

I have a large table of records that need joined againts three other databases depending on database_name. example data:


pk   db_name  data
1    db1     whatever else
2    db1     whatever else
3    db3     whatever else
7    db2     whatever else
8    db2     whatever else
10   db1    whatever else

those primary keys may only exist on that one db that it needs retreived from, or it may even be taken by another file that doesnt match with my data, Im not really sure. So either way i need to make sure my join is only with the proper db.

I’ll also be doing this daily, multiple times so I’d like to skip the step of making 3 seperate tables for the query (though this could maybe be done in the query?)

In any case any suggestions here would be appreciated.

Edit: I’d like to stay away from any make / drop table queries if possible.

Three separate databases? Or three separate tables? You sure it’s not the latter?

Sorry. Technically it is three seperate databases but our front end we access it through does make it accessible through different tables somehow.