Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

join between two databases

Status
Not open for further replies.

inarobis

IS-IT--Management
Joined
Apr 3, 2006
Messages
71
Location
CH
hello,

I have question about how to join to table from different databases.

How Can I do a map table between this two databases?

For example (in two different software)

table 1 database 1
clientcode

table1 database 2
clientNameCode

I would like to obtain this two data in one table how to do that?

Ina
 
Code:
SELECT Tbl1.ClientCode, Tbl2.ClientName
FROM DataBase1..Table1 Tbl1
LEFT JOIN DataBase2..Table1 Tbl2

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Thank you :)

could you explain me what means tbl1 and tbl2 before column
name.

There is any possibility to do a mapping table a table3 having the clientcode clientNameCode.

Ina
 
Ooops, I forgot to write Join Condition :-(. The code must be:
Code:
SELECT Tbl1.ClientCode, Tbl2.ClientName
FROM DataBase1..Table1 Tbl1
LEFT JOIN DataBase2..Table1 Tbl2
ON Tbl1.ClientCode = Tbl2.ClientCode

Tbl1 and Tbl2 are alias of the Tables used in SELECT. I added them just to make code shorter. If I didn't add them the code will looks like this:
Code:
SELECT DataBase1..Table1.ClientCode,
       DataBase2..Table1.ClientName
FROM DataBase1..Table1
LEFT JOIN DataBase2..Table1
ON DataBase1..Table1.ClientCode = DataBase1..Table1.ClientCode

Of course you can add as many tables as you need, just add a Database name from where you get them.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top