Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQL: Difference between inner join and outer join

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 332
    Comment on it

    Joins are used to combine the data from two tables and return specific rows of data from the tables.

    A join can be either an inner join or an outer join, depending on what is expected in the result.

    INNER JOIN:

    Gets all matching rows in BOTH tables

    LEFT JOIN:

    Gets all rows from the left table along with matching rows from the right table

    RIGHT JOIN:

    Gets all rows from the right table along with matching rows from the left table

    FULL JOIN:

    Gets all rows provided there is a match in ONE of the tables

    Let us say we have table X with data as below:

    X
    1
    2
    13
    14

    Let us say we have table Y with data as below:

    Y
    11
    12
    13
    14

    Following will be the result of INNER JOIN :

    X Y
    13 13
    14 14

    Following will be the result of LEFT OUTER JOIN :

    X Y
    1 null
    2 null
    13 13
    14 14

    Following will be the result of RIGHT OUTER JOIN :

    X Y
    null 11
    null 12
    13 13
    14 14

    Following will be the result of FULL OUTER JOIN :

    X Y
    1 null
    2 null
    13 13
    14 14
    null 11
    null 12

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: