Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2009
    Location
    Sydney
    Posts
    13

    Unanswered: return one result set from 2 queries

    Say I have 2 tables, but in this particular instance I am only interested in columns which are equivalent in both of them

    for e.g.

    table A

    id | status | other column which I'm not interested in
    ______________________
    a1 | good | whatever
    a2 | bad | whateversdlsf
    a3 | good | something

    table B

    id | status | a different column to other column above
    ______________________
    b1 | good | lalala
    b2 | bad | junk data
    b3 | good | not interesting

    and what I want is

    results

    id | status
    _________
    a1 | good
    a2 | bad
    a3 | good
    b1 | good
    b2 | bad
    b3 | good

    how can I return the rows like this?

    I can guarantee that the primary keys of table a & table b never clash

    (I am using db2 9.5)

  2. #2
    Join Date
    May 2009
    Posts
    508
    Provided Answers: 1
    gamo, Unless I am missing something, this should work:
    Code:
    SELECT ID, STATUS
    FROM TABLE_A
    UNION ALL
    SELECT ID, STATUS
    FROM TABLE_B
    ORDER BY ID, STATUS
    I added the ORDER BY to sort the results.

  3. #3
    Join Date
    Jul 2009
    Location
    Sydney
    Posts
    13
    ah - union - so obvious...now I feel a bit silly...

    thanks!!

Posting Permissions

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