August 4, 2009 at 5:25 am
Hi all,
I have a question on outer join and inner join. I have a query below it has outer and inner join. I dont know which join executes first. I know that it's a bit question but i got confused while working on this.
select * from
dbo.demog dm right outer join dbo.packlist pl inner join dbo.kittype kt
on pl.kittype = kt.kittype
on dm.siteid = pl.siteid
Thanks in advance
August 4, 2009 at 6:19 am
This is a nested join. To make it readable I would recommend that you always use brakets:
SELECT *
FROM dbo.demog dm
RIGHT JOIN
(
dbo.packlist pl
JOIN dbo.kittype kt
ON pl.kittype = kt.kittype
)
ON dm.siteid = pl.siteid
ie demog is RIGHT JOINed to the result of the INNER JOIN between packlist and kittype.
Personally I would re-write this to avoid the nested join:
SELECT *
FROM dbo.packlist pl
JOIN dbo.kittype kt
ON pl.kittype = kt.kittype
LEFT JOIN dbo.demog dm
ON pl.siteid = dm.siteid
August 5, 2009 at 12:42 am
Thanks! you mean the inner join executes first.
Could u clear its executing first because of order of the join we are using? or likely its executes the inner join first?
August 5, 2009 at 1:53 am
Logically the INNER JOIN is done first. ie The INNER JOIN is the nested join.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply