Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Databases > Re: Comparing 2...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 3688 of 3782
Post > Topic >>

Re: Comparing 2 tables

by David Harper <devnull@[EMAIL PROTECTED] > Mar 28, 2008 at 07:05 AM

m wrote:
> Hi All
> 
> I need to compare 2 tables ( I need to eliminate 2 columns in the
> table while comparing, they are dates and userids which wil be
> different. )
> 
> Example:
> 
> TableA( colA, colB, colC, colD, colE)
> TableB( colA, colB, colC, colD, colE)
> 
> I need to compare TableA and TableB , for me they are equal if
> contents of colA, colB, colC are same , need not compare colD and
> colE.
> 
> I write jdbc program which reads tables and compare row by row, just I
> think it is laborious. Is there a better way of doing this. Please let
> me know.

You may want to consider a left join between the two tables, along the 
lines of

   select TableA.*,TableB.* from TableA left join TableB on
     (TableA.colA = TableB.colA and TableA.colB = TableB.colB and
      TableA.colC = TableB.colC)
   where TableB.colD is null or TableB.colE is null;

This will show you which rows in TableA are not equal (by your criteria) 
to rows in TableB.

You probably need to repeat the query exchanging TableA and TableB to 
find rows in TableB which are not equal to rows in TableA.

This assumes, of course, that the triples (colA,colB,colC) are unique in 
each table i.e. there is only one row in TableA with any given 
combination of (colA,colB,colC) and likewise with TableB.

David Harper
Cambridge, England
 




 4 Posts in Topic:
Comparing 2 tables
m <modhak@[EMAIL PROTE  2008-03-27 22:00:32 
Re: Comparing 2 tables
David Harper <devnull@  2008-03-28 07:05:54 
Re: Comparing 2 tables
Roedy Green <see_websi  2008-03-28 12:33:00 
Re: Comparing 2 tables
Lew <lew@[EMAIL PROTEC  2008-03-28 22:23:37 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 5 15:14:41 CDT 2008.