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)
 Inner Join

Author  Topic 

Thiyagu_04
Starting Member

37 Posts

Posted - 2008-12-31 : 05:26:48
Hi
I am having 2 tables,Table1 and Table2.
Table1 having primary key and Table2 having foreign Key.
While doing inner join which is better

option1
Select * from Table1 t1 Inner join Table2 t2 on T1.CusID=T2.CusId

option2
Select * from Table2 t2 Inner join Table1 t1 on T2.CusID=T1.CusId

and also i want to know why its better.

Thanks in advance

raky
Aged Yak Warrior

767 Posts

Posted - 2008-12-31 : 05:32:48
I think both options are ok incase of Inner join
but i prefer 1st option because joining column custid is primary key in table1 so i prefer from table as Table1
Go to Top of Page

Thiyagu_04
Starting Member

37 Posts

Posted - 2008-12-31 : 05:41:26
Thanks for the reply.
Why first option is prefered is there any performance improvement.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2008-12-31 : 05:42:55
inner join will be consider as 1-1 relation ship (columns being joined are compared )

ur both queries will give same output and better
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2008-12-31 : 05:46:25
Both queries yield same output

But as raky suggested prefer first table table1

Jai Krishna
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-31 : 06:33:22
the execution plan is same for both queries too. So the order is not important
Go to Top of Page
   

- Advertisement -