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
 Multiple Joins

Author  Topic 

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2011-01-10 : 12:32:26
Hi -

I need data from 3 different tables, I am making multiple joins between the tables. This is what I have thus far, it is running but seems to be very inefficient.

dw.dbo.PremiumBilling pb inner join dw.dbo.sponsordemographics sd on pb.sponsorid = sd.sponsorid, dw.dbo.PremiumBilling pb2 inner join dw.dbo.sponsorpolicy sp on pb2.policynumber = sp.policynumber

Is this even correct? What can I do to speed it up??

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-10 : 12:42:21
its not correct as it has a cross join in between. probably you meant this?


...
dw.dbo.PremiumBilling pb
inner join dw.dbo.sponsordemographics sd
on pb.sponsorid = sd.sponsorid
inner join dw.dbo.sponsorpolicy sp
on pb.policynumber = sp.policynumber


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2011-01-10 : 12:48:17
Yes, that is what I meant. Thanks!!
quote:
Originally posted by visakh16

its not correct as it has a cross join in between. probably you meant this?


...
dw.dbo.PremiumBilling pb
inner join dw.dbo.sponsordemographics sd
on pb.sponsorid = sd.sponsorid
inner join dw.dbo.sponsorpolicy sp
on pb.policynumber = sp.policynumber


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-10 : 12:50:21
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2011-01-10 : 12:51:42
what is a cross join?
quote:
Originally posted by visakh16

its not correct as it has a cross join in between. probably you meant this?


...
dw.dbo.PremiumBilling pb
inner join dw.dbo.sponsordemographics sd
on pb.sponsorid = sd.sponsorid
inner join dw.dbo.sponsorpolicy sp
on pb.policynumber = sp.policynumber


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-10 : 13:03:03
cross join is equivalent to cartesian product. ie it returns all possible combinations of resultset from two queries

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -