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!

SQL help with Joins

Discussion in 'General' started by virusx1984, Jan 29, 2011.

  1. virusx1984

    virusx1984 Active Member

    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    80
    I have two table :
    Table A
    pn|sent
    A|3000
    B|3000
    C|3000
    D|3000

    and Table B
    pn|recieved
    A|1000
    C|2000

    I want to query the table like:
    pn|sent|recieved
    A|3000|1000
    B|3000|0
    C|3000|2000
    D|3000|0

    I have tried the sql : "select A.pn,sent,recieved from A,B where A.pn=B.pn " .
    but the result which is not wanted display:
    pn|sent|recieved
    A|3000|1000
    C|3000|2000

    the pn of A and B didn't show up. so I have to add them by hand.

    Is there a sql can accomplish that?
     
  2. Sadik

    Sadik Community Moderator Forum Guru

    Messages:
    1,906
    Likes Received:
    252
    Trophy Points:
    1,455
    virusx1984 likes this.
  3. virusx1984

    virusx1984 Active Member

    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    80
    Thanks I see
     
  4. janste

    janste Active Member

    Messages:
    23
    Likes Received:
    6
    Trophy Points:
    90
    Could this be the right query:

    Select A.Pn,A.Sent,Received
    From A Left Join B
    on a.pn=b.pn;
     
    virusx1984 likes this.
  5. janste

    janste Active Member

    Messages:
    23
    Likes Received:
    6
    Trophy Points:
    90
    or to get exactly the same output add the nvl function like this:

    Select A.Pn,A.Sent,nvl(b.received,'0') Received
    From A Left Join B
    on a.pn=b.pn;
     
    virusx1984 likes this.