Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2011
    Posts
    10

    Unanswered: To compare two tables in db2

    what is the query to compare values in two different tables which contains same column name and datatype?
    Eg:
    TAB1
    ID COL1 COl2 Col3
    1 A A A
    2 B B B
    3 C C C
    4 A A A

    TAB2
    ID COL1 COl2 Col3
    1 A A A
    2 B B B
    3 C D C
    4 A A A


    Output should be :

    ID COL1 COl2 Col3
    3 C C C
    3 C D C

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    A little modification for an example by Peter in this thread may give you an answer.
    http://www.dbforums.com/db2/1668809-...ables-db2.html
    Last edited by tonkuma; 08-03-11 at 02:13.

  3. #3
    Join Date
    Aug 2011
    Posts
    10
    Thanks fro ur reply..
    I got this doubt solved with this query.. Peter's query was also working fine..

    SELECT ID,COL1,COl2,COl3,count(*)
    FROM
    (


    SELECT A.ID, A.COL1,A.COL2,A.COL3
    FROM TAB1 A

    UNION ALL

    SELECT B.ID, B.COL1,B.COL2,B.COL3

    FROM TAB2 B
    ) TMPTBL
    GROUP BY
    ID,COL1,COL2,COl3

    HAVING COUNT(*) <> 2
    ORDER BY ID

Posting Permissions

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