Prefix with database name

If you made a query on db_global.tableXXX with subquery on wp_2_posts (for example ) that doesn’t work.

So is there a way to add a function wich prefix db name in the query ?

Or have separated function wich return database name with blogid ?