1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Left Join troble

Discussion in 'SQL PL/SQL' started by Alexey.Samoilov, Feb 25, 2015.

  1. Alexey.Samoilov

    Alexey.Samoilov Active Member

    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    55
    Hello, my friends!
    I have a little trouble.
    My tables are:

    Table A:
    Column1
    ----------
    1
    2
    N/A
    N/A
    3
    2

    Table B:
    Column1 Column2
    ------------------------
    1 F
    2 D

    I want to use Left join and give the next result:

    Result Table:
    Column1 Column2
    ------------------------
    1 F
    2 D
    N/A NULL
    N/A NULL
    3 NULL
    2 D

    But i can't with left join

    Code (Text):
    SELECT
    a.Column1,
    b.Column2
    from Table A left outer join Table B on a.Column1 = b.Column1;
    Can you help?
     
  2. RG Hegde

    RG Hegde Forum Advisor

    Messages:
    185
    Likes Received:
    35
    Trophy Points:
    310
    Location:
    Pune
    Hello Alexey,

    it will display proper output with left outer join.

    COL1 COL2

    1 F
    2 D
    2 D
    N/A
    N/A
    3

    May I know what output you are getting?
     
  3. RG Hegde

    RG Hegde Forum Advisor

    Messages:
    185
    Likes Received:
    35
    Trophy Points:
    310
    Location:
    Pune
    Hello

    If you would like to display the output as 'NULL' you can use
    Code (SQL):
    SELECT
    a.Col1,
    nvl(b.Col2,'NULL') col2
    FROM tableA a LEFT OUTER JOIN tableB b  ON a.Col1 = b.Col1;
    The output will be
    COL1 COL2

    1 F
    2 D
    2 D
    N/A NULL
    N/A NULL
    3 NULL