Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 joining tables?

Author  Topic 

sqlclarify
Yak Posting Veteran

56 Posts

Posted - 2008-09-17 : 17:20:41
I have 5 tables. A,B,C,D,E

I have joined them in the following way..

A->B
B->C
C->D
D->E

If I join them as
A->B
A->C
A->D
A->E
will that change the meaning of the query?

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-09-17 : 18:27:13
it depends on what columns you are joining on.


elsasoft.org
Go to Top of Page

sqlclarify
Yak Posting Veteran

56 Posts

Posted - 2008-09-19 : 13:29:52
A contains the foreign keys of B,C,D,E
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-09-19 : 13:34:57
how about you post the DDL for the tables, and the DML for query?


elsasoft.org
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-20 : 02:07:18
quote:
Originally posted by sqlclarify

A contains the foreign keys of B,C,D,E


then you should be using the latter one
Go to Top of Page

sqlclarify
Yak Posting Veteran

56 Posts

Posted - 2008-09-20 : 21:47:25
Why should we use the latter one? What difference does it make?

Could you please explain the reasoning?

I am new to databases so I would like to know why this makes a difference.

Thank you!
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-09-20 : 23:13:22
Assuming they are all INNER JOINs (on the same columns with either method) then I don't believe the results will be different. Depending on the indexes, the optimizer may come up with a better plan one way or the other. You can always compare the results from both methods to see for yourself.

Be One with the Optimizer
TG
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-21 : 01:31:03
quote:
Originally posted by sqlclarify

Why should we use the latter one? What difference does it make?

Could you please explain the reasoning?

I am new to databases so I would like to know why this makes a difference.

Thank you!


i told use latter one since you've specified A contains foreign keys of B,C,D & E. So the relationship will be A->B,A->C,A->D & A->E
Go to Top of Page
   

- Advertisement -