SQL LEFT JOIN.

SQL using RIGHT JOIN.

  • LEFT JOIN - Return all rows from the left table, even if there are no matches in the right table of two tables joined.

    Pictorial representation :

  • LEFT JOIN and LEFT OUTER JOIN are the same.
  • A skeleton version of LEFT JOIN syntax is this:
    SELECT select_list
    FROM table_1 LEFT [OUTER] JOIN table_2
    ON [table_1.]column  join_operator  [table_2.]column
    [WHERE search_conditions ]
    [ORDER BY column1, column2, ... ]
    Example using LEFT JOIN between the tables:
    SQL server, MySQL, Oracle, PostgreSQL :
    Select a.US_STATE_CD "Addresses code", ADDR_LINE "Address",
            CITY, u.US_STATE_CD "State code", US_STATE_NM 
     from US_STATES u
     LEFT OUTER JOIN ADDRESSES a
     ON a.US_STATE_CD=u.US_STATE_CD
    WHERE US_STATE_NM LIKE 'A%'
    ORDER BY u.US_STATE_CD;
    The result should be:
    Addresses code Address city State code us_state_nm
    AK Alaska
    AL Alabama
    AR 3009 Table Rock Road Biglerville Alleene AR Arkansas
    AR 3009 Table Rock Road Biglerville Alleene AR Arkansas
    AZ Arizona
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.