Just fully qualify the names, like this:
select a.id, b.id from db1.dbo.test a inner join db2.dbo.test b on a.id=b.id
If you set up a linked server, you can even do this across servers by using four part syntax:
select a.id, b.id from db1.dbo.test a inner join DifferentServer.db2.dbo.test b on a.id=b.id
Andy