Friday, January 28, 2011

OUTER JOINS

    LEFT OUTER JOINS

    Let take we have two tables A and B. The left outer joins will return all the rows from the left table A in conjunction with the matching rows from the right table B. In case there are no columns matching in table B, it returns NULL values.

    Example:

    clip_image001

    clip_image002

    There will be 122 rows returned (there are some departments without employees to be assigned to so there are entries with NULL values in columns FIRST_NAME, LAST_NAME)

    If we just change left and right table the result will be different:

    clip_image003

    There are 107 rows returned (number of rows present in table EMPLOYEES)

    clip_image004

    There are 107 rows returned (number of rows present in table EMPLOYEES)

    RIGHT OUTER JOINS

    I am taking again two tables A and B. The right outer joins will return all the rows from the left table B in conjunction with the matching rows from the right table A. In case there are no columns matching in table A, it returns NULL values. Example:

    clip_image005

    clip_image006

    There will be 122 rows returned

    If we change the table places will get different result

    clip_image007

    `There will be 107 rows returned (number of rows in EMPLOYEES table)

    FULL OUTER JOINS

    It combines both left outer and the right outer joins together.

    clip_image008

    clip_image009

    There will be 123 rows returned (there are some departments without employees to be assigned to so there are entries with NULL values in columns LAST_NAME, SALARY )

No comments:

Post a Comment