Solved

Inner Joining  3 tables from 3 different databases

Posted on 2010-01-07
5
236 Views
Last Modified: 2012-05-08
Does anyone have sample sql statement, using  -- Inner Joining  3 tables from 3 different databases  ?
Please

Very hard to find these types of examples...

Thanks
fordraiders
0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 26200135
select d1.field, d2.field, d3.field
from
database1.dbo.tablename d1
join database2.dbo.tablename d2 on d1.field2 = d2.field2
join database3.dbo.tablename d3 on d2.field3 = d3.field3

make sense?
0
 
LVL 6

Accepted Solution

by:
hyphenpipe earned 250 total points
ID: 26200152
If all the databases are in the same instance then it would be:

select * from first_table f
inner join database_name..second_table s on f.[column_name] = s.[columns_name]
inner join database_name..third_table t on s.[column_name] = t.[columns_name]

If they are in separate instances then you would need to add them as linked servers and then it would be:

select * from first_table f
inner join linked_server.database_name.dbo.second_table s on f.[column_name] = s.[columns_name]
inner join linked_server.database_name.dbo.third_table t on s.[column_name] = t.[columns_name]
 
0
 
LVL 3

Author Comment

by:fordraiders
ID: 26200622
Yes, They are in the same "instance".

Here is what works for 2 tables from 2 different databases..

select SKU_VIEW.ITEM,
       SKU_VIEW.WWGMFRNAME,
       SKU_VIEW.WWGMFRNUM,
       WWGDESC_ALL.dbo.WwgDescRich.RICHTEXT
      from ITEM_DISPLAY.dbo.SKU_VIEW INNER JOIN WWGDESC_ALL.dbo.WwgDescRich ON
ITEM_DISPLAY.dbo.SKU_VIEW.ITEM = WWGDESC_ALL.dbo.WwgDescRich.ITEM


I would like to do the same with another table from another databases.

Database =   XrefInfo
Table name =  dbo.XrefDetail
pk column =     ITEM
Field I need in the query =  REDBOOKNUM

Sorry ,  Guess I should have added this to the question..

Thanks
fordraiders

 




0
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 250 total points
ID: 26200705
select SKU_VIEW.ITEM,
       SKU_VIEW.WWGMFRNAME,
       SKU_VIEW.WWGMFRNUM,
       WWGDESC_ALL.dbo.WwgDescRich.RICHTEXT,
XrefInfo.dbo.Xrefdetail.Redbooknum
      from ITEM_DISPLAY.dbo.SKU_VIEW INNER JOIN WWGDESC_ALL.dbo.WwgDescRich ON
ITEM_DISPLAY.dbo.SKU_VIEW.ITEM = WWGDESC_ALL.dbo.WwgDescRich.ITEM
JOIN XrefInfo.dbo.Xrefdetail ON WWGDESC_ALL.dbo.WwgDescRich.Item = XrefInfo.dbo.Xrefdetail .Item
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 31674009
Thanks to all !
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question