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
 Join Mutliple Tables

Author  Topic 

Rheinhardt
Yak Posting Veteran

66 Posts

Posted - 2009-04-14 : 09:19:53
Hi,

How do I join more than one table setting the first tables Primary key column as the base ?

Table1 join Tbale2 join Table3 join Table4
1 1 1 1
2 2 2 2
3 3 3

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-04-14 : 09:47:19
use JOINs, If the data exist in both tables, you want INNER JOIN, if you want all data from the left table, but only those ont he right that existy in the left, then you want LEFT JOIN.

Look up joins in BOL (Books Online) or here:

http://msdn.microsoft.com/en-us/library/ms191517.aspx

Go to Top of Page

Rajesh Jonnalagadda
Starting Member

45 Posts

Posted - 2009-04-15 : 02:34:30
Hi

This is sample code and you can write as per your requirments,
for more info follow the MSDN link given by RickD

SELECT *
FROM Table1 A
JOIN Table2 B
On A.ID = B.ID
JOIN Table3 C
On B.ID = C.ID
JOIN Table4 D
On C.ID = D.ID


Rajesh Jonnalagadda
[url="http://www.ggktech.com
"]GGK TECH[/url]
Go to Top of Page
   

- Advertisement -