Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to join two data base in table sql
Posted

Try this:
SQL
SELECT 
a.userID, 
b.usersFirstName, 
b.usersLastName  
FROM databaseA.dbo.TableA a 
JOIN database B.dbo.TableB b 
ON a.userID=b.userID

Found it here[^]
 
Share this answer
 
Try below sql


SQL
SELECT a.columnname,b.columnName  FROM databaseA.dbo.TableA a inner join database B.dbo.TableB b  ON a.ID=b.ID
 
Share this answer
 
If the databases are on the same instance (server) then all you need to do is fully qualify the table names. For example ...
SQL
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900