dcsimg
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: comparing tables

  1. #1
    Join Date
    Apr 2001
    Location
    Congleton
    Posts
    258
    I am trying to compare 2 tables, to check if the same transaction number is used in either table.

    I have tried
    select * from table1 a
    where exists (select 1 from table2 b
    where a.trans=b.trans)
    but how can I specify a query to do the check on both tables at the same time?

  2. #2
    Join Date
    Nov 2001
    Location
    UK
    Posts
    152
    Is transaction_number unique ? Why don't you just join the tables:

    select * from table1 a, table2 b
    where b.trans = a.trans

    This will only give you rows which are common to both tables.

  3. #3
    Join Date
    Jan 2002
    Posts
    10
    Scorby,

    You could try this extension to your code....

    select * from table1 a
    where exists (select 1 from table2 b
    where a.trans=b.trans union select 2 from table3 c
    where c.trans=a.trans )

    !


    ssmith, your code would probably return a "true" iif the 'join' evaluates to a true on both the tables(b & c) and may not go with Scorby's "either" clause..



    Mahesh.

Posting Permissions

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


Click Here to Expand Forum to Full Width