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)
 Select sql join!!

Author  Topic 

agarwasa2008
Posting Yak Master

109 Posts

Posted - 2009-09-04 : 17:35:58
I have 3 tables:

Table1 - someName and complete productIDs
Table2 - Name and productID
Table3 - DifferentName and productID

Table2 and table3 have some common and some unique ids. For ex

Table2
======
1234567 Chair
0987654 Table

Table3
======
1234567 cushions
5555555 Desk

Table1
======
1234567 item1
0987654 item23
5555555 item45

Result set
==========
1234567 Chair cushions item1
0987654 Table NULL item23
5555555 Null Desk item45

Any inputs would be greatly appreciated.

Thanks,



SA

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-04 : 17:44:59
select t1.productid,t2.productname,t3.productname,t1.productname
from table1 t1
left join table2 t2 on t2.productid = t1.productid
left join table3 t3 on t3.productid = t1.productid


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

agarwasa2008
Posting Yak Master

109 Posts

Posted - 2009-09-04 : 19:21:19
whats the difference between using left join and left outer join

Thanks, for the prompt response.


SA
Go to Top of Page

singularity
Posting Yak Master

153 Posts

Posted - 2009-09-04 : 19:29:22
There is no difference.
Go to Top of Page

agarwasa2008
Posting Yak Master

109 Posts

Posted - 2009-09-04 : 19:59:14
Thank you!!


SA
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-05 : 05:44:11
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -