Solved

Inner Joining  3 tables from 3 different databases

Posted on 2010-01-07
5
205 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
  • 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
select over clause 1 40
Syntax using Declare 4 38
Distributed Replay - When should i use it? 1 24
Can Unique column have more than one Null? 8 43
Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now