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 7 tables into one

Author  Topic 

er.bhupinder53
Starting Member

13 Posts

Posted - 2011-07-05 : 20:14:37
Hi,

I have to join 7 tables in one driver table table. 5 tables have a common column named A with other different columns and rest 2 tables have a common column named B with other different columns.

Kindly suggest me how to join these 7 tables.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-07-05 : 20:19:59
The general syntax is as follows, you can extend it to however many columns. But whether you should use an inner join, or a left/right/full outer join depends on your needs.

select
a.colA, a.col2,.. a.colN,
b.colA, b.col2,.. b.colN,
c.colA, c.col2,.. c.colN
from
TableA a
inner join TableB b on a.colA = b.colA
inner join TableC c on a.colA = c.colA
If you need more specific help, post the table DDL, along with some sample data. Brett's blog may help: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

er.bhupinder53
Starting Member

13 Posts

Posted - 2011-07-05 : 20:31:55
I want all the rows to appear in resulted table.
like if 7 tables have 10 different rows each. then I should get 70 rows in one table.
join will do the matching and then produce the result.

Thanks !
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-07-05 : 20:54:22
It sounds like you want a cross join, but your post is really unclear. Please show us a simple data example of what you want so we can help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -