I need to reconcile the data in two tables using Java.
The data in the first table will be inserted via an Excel sheet upload. The data is number of users in the company.
The data in the second table is inserted via users from the Java based web application. This can be new users added to company or users leaving the company.
So, if Excel sheet says we have 100 users in company and front end users add 2 new users and remove 5 users. Reconcile should give total count of users in company (count = 97) with the classification of existing users, new users joined and users who have left.
What will be database structure and what will be reconcile query.
Please help.
Please, specify which database you are using. Also, please specify what data would be imported from the Excel file and what information would be provided via the web application.
In general, you most likely need a simple INSERT
and a DELETE
statement. (MERGE
probably cannot be used efficiently/elegantly here; it can insert and delete within one statement, but it can delete rows only if they have been updated before).
Your first table would have columns that reflect the structure of the Excel table; the second one would have the same structure/column plus one more column perhaps that would indicate whether it's a new user or a leaving one (for new users all required column values needs to be provided, for leaving ones a user ID or some similar unique value would be sufficient).
In round one you insert the new user data from the second table to the first one, in the second one, you delete the user rows from first table whose user ID is listed in the second table as leaving ones. Then you delete all rows from second table to ensure that these changes will not be applied again. Then you commit the transaction (I hope AUTOCOMMIT
is not enabled...).