Results 1 to 3 of 3

Thread: Join 2 tables

  1. #1
    Join Date
    Oct 2005
    Posts
    92

    Unanswered: Join 2 tables

    Hi All,

    There are 2 tables with data as below. The column 'ID' is the available in both tables. can someone please help me how do i get the desired output.
    Table 1:

    ID IND
    101 Y
    102 N

    Table 2:

    ID CD
    101 A
    101 B
    101 C
    101 D
    102 A

    Desired output:

    ID CD IND
    101 A Y
    101 B
    101 C
    101 D
    102 A N

    Thanks
    pavan

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    It would be helpful if you posted CREATE TABLE statements for both tables.
    It would be helpful if you posted INSERT statements to populate rows into both tables.
    Please explain the logic as to why ID=101 & CD=A row get the 'Y'
    Please explain the logic as to why ID=102 & CD=A row get the 'N'
    Please explain the logic as to why the remaining rows get neither "Y" nor "N".
    What should occur when TABLE1 contains a new row ID=103 & IND=Q?
    What should occur when TABLE1 contains a new row ID=102 & IND=Y?
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    You really should provide total info like anacedent requested when asking for others to help you. Not knowing any of the answers to anacedent's questions I can still give you exactly what you ask for , but it may not be right.

    Code:
    select id, cd, ind
    from table1
    left outer join table2
      on table1.id = table2.id 
     and table1.cd = 'A'
    Dave

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •