Friday, March 9, 2012

multiple table joins, does the "ON" clause determine which two

Thanks for the response.
Those are the "real" tables. I was doing an exercise in trying to figure out
as many ways as I could to do the "minus" operation on three tables.
I am trying to go to the next level of DB programming, that is move up from
basic SQL queries. I was reading about "translation" or "intermediate" table
s
when you do joins and I didn't really understand when such a table comes int
o
existance.
Here is what I was reading:
http://msdn.microsoft.com/library/d...r />
_0hwz.asp
"The middle table of the join (the titleauthor table) can be called the
translation table or intermediate table, because titleauthor is an
intermediate point of connection between the other tables involved in the
join.
When there is more than one join operator in the same statement, either to
join more than two tables or to join more than two pairs of columns, the joi
n
expressions can be connected with AND or with OR."
"Jens Sü?meyer" wrote:

> SELECT T1.ID
> FROM T1
> LEFT OUTER JOIN T2
> on T1.ID = T2.ID
> LEFT OUTER JOIN T3
> ON T1.ID = T3.ID
> WHERE (T2.ID IS NULL) AND (T3.ID IS NULL)
> There is no "intermediate" table as I would think about that in an n:m
> realtionsship. As it seems, the tabels all have the same primary keys whic
h
> sounds that they don′t build up a many2many relationship. (Perhaps if you
> would post up your real example and some DDL that would clarify the
> situation a bit)
>
> I always put tabs between the expression to chop up the important parts of
> th query. (see above)
> --
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
> "Geoff" <Geoff@.discussions.microsoft.com> schrieb im Newsbeitrag
> news:3D111A57-3DB2-4202-A6BD-F1530880A665@.microsoft.com...
>
>But taht depends on your design wheter you have a 1-n or n-m relationship.
1-n One Customer can have multiple orders.
n-m One Author can write multiple book, but one book can be written by
multiple authors, therefore you need this intermediate table where you make
the connection between the values:
AUTHORS
========
AuthId AuthorName
1 Jens Smeyer
2 Peter Gedoens
BOOKS
======
BookId BookName
1 YourExampleBook
2 SQL Server the curse of relationals
3 Oracle sucks
AuthorBooks
=========
AuthorId BookId
1 1
2 1
1 2
1 3
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Geoff" <Geoff@.discussions.microsoft.com> schrieb im Newsbeitrag
news:EEA9BA2B-F086-4F4C-8A5B-C7788F033D9D@.microsoft.com...
> Thanks for the response.
> Those are the "real" tables. I was doing an exercise in trying to figure
> out
> as many ways as I could to do the "minus" operation on three tables.
> I am trying to go to the next level of DB programming, that is move up
> from
> basic SQL queries. I was reading about "translation" or "intermediate"
> tables
> when you do joins and I didn't really understand when such a table comes
> into
> existance.
> Here is what I was reading:
> http://msdn.microsoft.com/library/d.../>
09_0hwz.asp
> "The middle table of the join (the titleauthor table) can be called the
> translation table or intermediate table, because titleauthor is an
> intermediate point of connection between the other tables involved in the
> join.
> When there is more than one join operator in the same statement, either to
> join more than two tables or to join more than two pairs of columns, the
> join
> expressions can be connected with AND or with OR."
>
>
>
> "Jens Smeyer" wrote:
>

No comments:

Post a Comment