File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Compare Two Column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Compare Two Column" Watch "Compare Two Column" New topic

Compare Two Column

Rashmi Trivedi
Ranch Hand

Joined: Aug 13, 2001
Posts: 60
Hi Guys
This is what i am trying to do...I have 1 table calledd...User_LOGIN and it has 2 it LOGON1 and LOGON2...i want to compare these two column and find out which record is missing and produce txt file with the missing one...
I have one record which has all the records from column 1 and another record set with all the records from column 2...
now i am struggling as to how do i compare these two record set...
Could you give me some how should i do this...
I do appreciate ur time and consideration...
Faisal Khan
Ranch Hand

Joined: Jun 29, 2003
Posts: 285
I don't think this post is anything to do with Servlets, rather it is SQL. I am not entirely sure, what you are trying to achieve but if its to compare two tables and find out what is missing in one, you can do the following (I am using MySQL):
SELECT t1.col1, t1.col2
FROM table1 t1
LEFT JOIN table2 t2
ON t1.col1 = t2.col1
WHERE t2.col1 IS NULL;

The secret to creativity is knowing how to hide your sources.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I think you said you were comparing record sets - the results of two queries. The basic algorithm for this goes back to the ancient geeks of mainframe batch days:

End of file (set) can be handled a couple ways. One is to set an impossibly high key so the key comparisions keep working. Another is to add EOF tests to the comparisons: if A Key < B Key or B EOF ...
I wrote a little program that does this logic on any two result sets. You tell it how many columns are involved in the key and make sure those columns are left-most in each row. Pretty cool to compare data or meta-data between two versions of a database.
Was that what you were asking?

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

This appears to be related to Databases and is not specific to Servlets. I'm moving it to the JDBC forum.
I agree. Here's the link:
subject: Compare Two Column
jQuery in Action, 3rd edition