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
 General SQL Server Forums
 New to SQL Server Programming
 I don't know how to JOIN more than two tables..!!!

Author  Topic 

ZarrinPour
Yak Posting Veteran

66 Posts

Posted - 2008-01-12 : 15:01:56
Hi everybody
I know how to join two tables with [INNER JOIN] or [LEFT/RIGHT OUTER JOIN] Keywords ,But when i have more than two tables , always i mixed up and have difficulty to build the query specially when i have to use LEFT or RIGHT OUTER JOIN Keywords!!!
and that's why i always use SQL Server Query Builder and let it to make the query string for me. i couldn't understand how SQL SERVER build the [FROM] section of the query ,really what method (Algorithm) does it uses to Build the query String??? could anyone point me or give me some advices?
is there any book to this topic?

Thanks In Advance
Kind Regards.

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-01-12 : 15:22:20
select a.col1, b.col1, c.col1 from tablea a join tableb b on a.col1 = b.col1
join tablec c on a.col1 = c.col1 where ...
Go to Top of Page

ranjeetsingah
Starting Member

3 Posts

Posted - 2008-01-13 : 10:06:25
Hi ZarrinPour,

try this syntax i am sure your problem has been solved.

select a.invoice_no,a.bill_no
from dbo.Invoice a
left outer join
dbo.InvoiceDetail b
on a.invoice_no=b.invoice_no
where a.bill_no='Your Condition'



Ranjeet Singh
Software Engineer
Mobile- +91-9910893772
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2008-01-13 : 11:12:29
If you think of the query visually when creating your From statements it gets easier.

The table you want ALL records from is seen on the "LEFT" therefore everything you want joined to it would be FROM that table LEFT JOIN other table..

In the From statement you would create it the same way..

FROM [LeftSideTable] lft LEFT JOIN [RightTable1] rgt on lft.[Column] = rgt.[Column]
LEFT JOIN [RightTable2] rgt2 on lft.[Column] = rgt2.[Column]

The table on the left side of the join would be LEFT JOIN'ed to the tables on the right side of the statement itself.

Also, check here:
http://technet.microsoft.com/en-us/library/ms187518.aspx






Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page
   

- Advertisement -