Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2013
    Posts
    6

    Unanswered: please help with the sql

    Could you please help with me with the sql

    Task - Load data into new table C from table A and table B


    TABLE A has two columns where

    COL A is primary key (sequence number)

    ***********************
    COL A * COL B * COL C *
    ***********************
    1 10 10
    2 20 20
    3 40 30
    ***********************

    TABLE B
    ****************
    COL B * COL C *
    ****************
    10 TEN
    20 TWENTY
    30 THIRTY
    40 FORTY
    ****************


    RESULT :

    TABLE C

    ***********************
    COL A * COL B * COL C *
    ***********************
    1 TEN TEN
    2 TWENTY TWENTY
    3 FORTY THIRTY
    ***********************

  2. #2
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    what have you tried so far? we can give assistance, not do the task for you.

  3. #3
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Use LOAD command (or INSERT statement) with the following examples.

    Example 1:
    Code:
    SELECT a.col_a
         , b1.col_c AS col_b
         , b2.col_c AS col_c
     FROM  table_a AS a
     INNER JOIN
           table_b AS b1
      ON   b1.col_b = a.col_b
     INNER JOIN
           table_b AS b2
      ON   b2.col_b = a.col_c
    ;

    Example 2:
    Code:
    SELECT a.col_a
         , MAX( CASE a.col_b
                WHEN b.col_b THEN
                     b.col_c
                END
               ) AS col_b
         , MAX( CASE a.col_c
                WHEN b.col_b THEN
                     b.col_c
                END
               ) AS col_c
     FROM  table_a AS a
     INNER JOIN
           table_b AS b
      ON   b.col_b IN (a.col_b , a.col_c)
     GROUP BY
           a.col_a
    ;

  4. #4
    Join Date
    Jun 2013
    Posts
    6
    dav1mo,

    My Try was left join -

    SELECT A.COL A AS COL A, B.COL B AS COL B, B.COL B AS COL C
    FROM TABLE A LEFT JOIN ON TABLE B WHERE A.COL B = B.COL A AND A.COL C = B.COL A.

    thanks

    Tonkuma, thanks so much for the reply.

    correction in my request-
    the numbers of rows in table A should be same as table C

    TABLE A

    COL A is primary key (sequence number)

    ***********************
    COL A * COL B * COL C *
    ***********************
    1 10 10
    2 15 15
    3 20 20
    4 40 30
    5 0 0
    6 0 0
    ***********************

    TABLE B
    ****************
    COL A * COL B *
    ****************
    10 TEN
    20 TWENTY
    30 THIRTY
    40 FORTY
    ****************


    RESULT :

    TABLE C

    ***********************
    COL A * COL B * COL C *
    ***********************
    1 TEN TEN
    2
    3 TWENTY TWENTY
    4 FORTY THIRTY
    5
    6
    ***********************

  5. #5
    Join Date
    Jun 2013
    Posts
    6
    i tried again and it works with the left join

    thanks so much tonkuma

Tags for this Thread

Posting Permissions

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