Join tables from different databases on same SQL server
Posted on 2008-11-05
I have three tables, one from one database and two from another, both databases on the same SQL server: (The server name is M2MSERVER)
I want a SELECT statement to select certain fields from each of the three tables, the common field being ITEM_NO. The three tables have no other common field.
Each m2mdata03.dbo.inmast record can have multiple matches in both INMASSINVTXN.dbo.INMASSTXNS and m2mdata03.dbo.inonhd.
The result would, in effect, join the two m2mdata03 tables first, creating a combination record for every ITEM_NO in inonhd that has a matching ITEM_NO record in inmast.
Then it would, in effect, join that result for every record in INMASSTXNS that has a matching ITEM_NO in the inmast/inonhd result.
I know how to make this work when it involves only two tables and both are in the same database, but not how to deal with three tables and two databases in an SQL SELECT and JOIN statement.
Thanks for the help!