Outer join and inner join

  • 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

  • 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

  • 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?

  • 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