Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2008
    Posts
    26

    Unanswered: Merging data in two tables

    Hi,

    Did the following, is it logically correct. seems to produce the results correctly

    Code:
    select a.c_trx, b.ship,b.way, c.br from
     (select c_trx from test1
     union
     select c_trx  from test2) a,
     test1 b,
     test2 c
     where a.c_trx = b.c_trx
     and a.c_trx = c.c_trx
    just trying to find a simpler approach of achieving this
    Last edited by ajitpal.s; 12-21-08 at 21:44.

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    The homework tutor is down the hall through 2nd door on the left.

    I suggest you investigate OUTER JOIN
    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
    Nov 2008
    Posts
    26
    Quote Originally Posted by anacedent
    The homework tutor is down the hall through 2nd door on the left.

    I suggest you investigate OUTER JOIN
    lets say if i use the following, logically does it seem right? seems to produce the right results.

    Code:
    select a.c_trx, b.ship,b.way, c.br from
     (select c_trx from test1
     union
     select c_trx  from test2) a,
     test1 b,
     test2 c
     where a.c_trx = b.c_trx(+)
     and a.c_trx = c.c_trx(+)

    just trying to find the simpliest solution

  4. #4
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    You changed your original post significantly after my 1st response.
    Now there is no sample data or desired results.

    So how can anyone judge correctness or efficiency?

    You're On Your Own (YOYO)!
    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.

  5. #5
    Join Date
    Nov 2008
    Posts
    26
    Quote Originally Posted by anacedent
    You changed your original post significantly after my 1st response.
    Now there is no sample data or desired results.

    So how can anyone judge correctness or efficiency?

    You're On Your Own (YOYO)!
    Sorry, below is the sample data and output

    actually i have 2 tables

    test1 table has c_trx, ship, way as columns

    test2 table has c_trx, br as columns

    Data is as below

    test1

    c_trx, ship, way
    ----------------------
    1, 22, 1
    2, 33, 4

    test2

    c_trx, br
    ----------------------
    1, 4.0
    5, 2.0

    Actually im trying to merge both the results

    Meaning the output will return something like this

    c_trx, ship, way, br
    -------------------------------------------------
    1, 22, 1, 4.0
    2, 33, 4, null
    5, null,null,2.0

  6. #6
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    So - did you research use of OUTER JOIN, just as Anacedent suggested in the second post?

  7. #7
    Join Date
    Nov 2008
    Posts
    26
    Quote Originally Posted by Littlefoot
    So - did you research use of OUTER JOIN, just as Anacedent suggested in the second post?

    Hi,

    Yes, i did, this is what i have got

    Code:
    select a.c_trx, b.ship,b.way, c.br from
     (select c_trx from test1
     union
     select c_trx  from test2) a,
     test1 b,
     test2 c
     where a.c_trx = b.c_trx(+)
     and a.c_trx = c.c_trx(+)

    It does what i need, tested with small data result, it returns the data correctly.. just wondering if the sql above is ok, or is there any other better way of doing it

Posting Permissions

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