Pardon my newbieness.
I have four tables to join. I'll just call them Table1, Table2, Table3
and Table4.
Table1 is the main table. I want to do outer joins pointing from fields
in Table1 to fields in each of the other tables. So all records in
Table1 regardless of whether they match in the other tables.
todSelect t1.* from Table1 t1
LEFT JOIN Table2 t2
ON t1.SomeiD = t2.someID
LEFT JOIN Table3 t3
ON t1.SomeiD = t3.someID
...
HTH, Jens Suessmeyer,
http://www.sqlserver2005.de
--
"Tod" <todtown@.swbell.net> schrieb im Newsbeitrag
news:1115757100.280539.176950@.o13g2000cwo.googlegroups.com...
> Pardon my newbieness.
> I have four tables to join. I'll just call them Table1, Table2, Table3
> and Table4.
> Table1 is the main table. I want to do outer joins pointing from fields
> in Table1 to fields in each of the other tables. So all records in
> Table1 regardless of whether they match in the other tables.
> tod
>|||select * from
Table1 left join Table2 on Table1.fld1 = Table2.fld1
left join Table3 on Table1.fld1 = Table3.fld1
left join Table4 on Table1.fld1 = Table4.fld1
"Tod" wrote:
> Pardon my newbieness.
> I have four tables to join. I'll just call them Table1, Table2, Table3
> and Table4.
> Table1 is the main table. I want to do outer joins pointing from fields
> in Table1 to fields in each of the other tables. So all records in
> Table1 regardless of whether they match in the other tables.
> tod
>|||Conceptually. each "Join" is a join between only two "Relations", or
"Resultsets". When you have more than two tables in a From Clause, and,
therefore, you have two or more joins. the second "Join" that takes place ca
n
be thought of as a Join between the intermediate resultset created by the
first join, and the third table. So the answer to your question depends on
what order, and what exactly, you wish to Join in this second Join... (and
then the third Join...)
Two possibilities exist:
You could Join Tables B to A, using Outer Join syntax, and then Join C to
that resultset, also using Outer Join SyntAX...
From TableA
Left Outer Join Table B On .....
Left Outer Join Table C On ......
Or 2) you might be wishing to Join the COmbined Inner Join of Tables B & C
to Table A. In this case you would be joining B & C FIrst, and then Joining
THAT resultset to TableA using Outer Join Syntax
From TableA
Left Outer Join (Table B Join Table C On ....)
On ....
This approach might be used to get ALL Customers, (even the ones with no
Invoices), plus the data from a Invoices and connected Invoice Details table
s
, but only include invoices that have details...
"Tod" wrote:
> Pardon my newbieness.
> I have four tables to join. I'll just call them Table1, Table2, Table3
> and Table4.
> Table1 is the main table. I want to do outer joins pointing from fields
> in Table1 to fields in each of the other tables. So all records in
> Table1 regardless of whether they match in the other tables.
> tod
>
No comments:
Post a Comment