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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating VIEW with (3) tables 1

Status
Not open for further replies.

awholtsIT

IS-IT--Management
Aug 18, 2008
27
US
SQL Server 2005 STD SP1:

I want to add a field from third table [TABLE3].
TABLE3 can link to TABLE2 via a key Field [Field2].

I'm not sure how to correctly add a TABLE3 to the existing, and working properly joined TABLE1 and TABLE2 script.

Can this be done, and if so, what is the proper scripting, or what will the below script end up looking like?

Here is the existing view with (2) tables joined.
++++++++++++++++++++++++++
create view VIEW_TEST as
select a.field1,a.field2,a.field3,b.field1,b.field2
from TABLE1 a left outer join TABLE2 b on a.field1=b.field1
++++++++++++++++++++++++++

Thanks,

Andrew
 
Andrew,
You should just need to add the third table as a left outer join.

Code:
create view VIEW_TEST as
select a.field1,a.field2,a.field3,b.field1,b.field2
    from TABLE1 a 
left outer join TABLE2 b on a.field1=b.field1
left outer join table3 c on b.field2 = c.table2

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top