LEFT JOIN vs. LEFT OUTER JOIN in SQL Server, which one is better?
LEFT JOIN vs. LEFT OUTER JOIN in SQL Server, which one is better?
304
11-Jul-2023
Updated on 12-Jul-2023
Aryan Kumar
12-Jul-2023Both
left joinandleft outer joinare used to join two tables together, but there is a subtle difference between the two.A
left joinwill return all rows from the left table, even if there are no matching rows in the right table. Aleft outer joinwill also return all rows from the left table, but it will also return null values for the columns in the right table where there are no matching rows.In general,
left joinis used when you want to return all rows from the left table, regardless of whether there are matching rows in the right table.left outer joinis used when you want to return all rows from the left table, and you also want to return null values for the columns in the right table where there are no matching rows.Here is a table that summarizes the differences between
left joinandleft outer join:The best way to choose between
left joinandleft outer joindepends on your specific needs. If you only need to return all rows from the left table, then you should useleft join. If you also need to return null values for the columns in the right table where there are no matching rows, then you should useleft outer join.For example, the following code will use
left jointo join theCustomersandOrderstables:SQL
This code will return all rows from the
Customerstable, even if there are no matching rows in theOrderstable.The following code will use
left outer jointo join theCustomersandOrderstables:SQL
This code will also return all rows from the
Customerstable, but it will also return null values for theOrderIDcolumn in theCustomerstable where there are no matching rows in theOrderstable.