When or why would you use a right outer join instead of left?

后端 未结 11 680
小蘑菇
小蘑菇 2020-11-27 05:47

Wikipedia states:

\"In practice, explicit right outer joins are rarely used, since they can always be replaced with left outer joins and provide no additional functi

11条回答
  •  时光说笑
    2020-11-27 06:13

    The only time I would think of a right outer join is if I were fixing a full join, and it just so happened that I needed the result to contain all records from the table on the right. Even as lazy as I am, though, I would probably get so annoyed that I would rearrange it to use a left join.

    This example from Wikipedia shows what I mean:

    SELECT *  
    FROM   employee 
       FULL OUTER JOIN department 
          ON employee.DepartmentID = department.DepartmentID
    

    If you just replace the word FULL with RIGHT you have a new query, without having to swap the order of the ON clause.

提交回复
热议问题