Database Tutorial

Course Tutorial Site

Site Admin

Left Join

with 3 comments

The LEFT [OUTER] JOIN matches every row in one table against every row in another based on common values in one or a set of columns, like an INNER JOIN. It then also returns everything from the table on the left of the LEFT JOIN operator that was not returned as part of the match.

Another way to describe a LEFT JOIN is as an intersection between two rows of data plus all rows found in the left set not found in the right set. The formula uses a ∀ to indicate given any sets A and B, then A intersects (∩) B plus all rows in A not found in B. The Venn diagram and set notation depicts that definition.

The syntax of a LEFT OUTER JOIN and LEFT JOIN are equivalent because the OUTER keyword is optional in some databases and excluded in others. A LEFT JOIN is a filtered join of the conceptual Cartesian Product of two tables and a relative complement. The filter identifies the rows that have matching values in a pair of columns, or a pair of two or more column sets. The relative complement of the LEFT JOIN operator is the right relative complement.

A LEFT JOIN acts like a nested loop where you match a key from the outer loop against a key from the inner loop, while preserving all non-matching values from the outer loop. An example written in PHP is found at the bottom of this page.

Written by michaelmclaughlin

January 17th, 2010 at 10:24 pm

Posted in

3 Responses to 'Left Join'

Subscribe to comments with RSS or TrackBack to 'Left Join'.

  1. “ANSI SQL:89 syntax doesn’t support a LEFT [OUTER] JOIN. Oracle Corporation noted this problem and implemented an extension to ANSI SQL:89, which is known as Oracle Proprietary SQL (e.g., dubbed as such by Alice Rischert in Oracle SQL by Example).” add “This example does not work in other databases” please

    Andrew Thimmig

    4 Feb 10 at 2:42 pm

  2. After the first result set in the ANSI 92 example, it reads this…

    “The ORDINAL_ENGLISH table’s primary key column name differs from the ORDINAL_ENGLISH table’s primary key column name. The difference requires that you use the ON subclause.”

    I think you meant this:

    “The ORDINAL_ENGLISH table’s primary key column name differs from the ORDINAL_FRENCH table’s primary key column name. The difference requires that you use the ON subclause.”

    Cole

    31 Jan 15 at 8:54 pm

  3. Cole, Thanks. It’s fixed.

    michaelmclaughlin

    7 Mar 15 at 3:03 am

Leave a Reply