Join tables from different databases on same SQL server

I have three tables, one from one database and two from another, both databases on the same SQL server:  (The server name is M2MSERVER)
INMASSINVTXN.dbo.INMASSTXNS
m2mdata03.dbo.inmast
m2mdata03.dbo.inonhd

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!


Glenn StearnsAnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BrandonGalderisiCommented:
This is a select all, you can filter down the fields you want from there.

select * from m2mdata03.dbo.inmast t1
join INMASSINVTXN.dbo.INMASSTXNS t2
on t1.item_no = t2.item_no
join m2mdata03.dbo.inonhd t3
on on t1.item_no = t3.item_no
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Glenn StearnsAnalystAuthor Commented:
Thanks...as usual, I was trying too hard to write my script! Yours works great - really appreciate the quick reply!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.