July 14, 2009 at 2:51 pm
I have tables in one database with a link being user_id field to other tables in another database.
how do you connect two different databases to one query.
ie databaseA and databaseB
July 14, 2009 at 4:09 pm
Trout (7/14/2009)
I have tables in one database with a link being user_id field to other tables in another database.how do you connect two different databases to one query.
ie databaseA and databaseB
the key is to use the fully qualified names of the tables in each of the databases
SELECT *
FROM databaseA.dbo.AllUsers FirstAlias
LEFT OUTER JOIN databaseB.dbo.AllUsers SecondAlias
ON FirstAlias.user_id = SecondAlias.user_id
note you could do the same on a table on a different server, if you added that server as a linked server...then you would have a 4 part name:
ServerName.DatabaseName.dbo.Tablename, for example.
Lowell
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply