Show only new and removed records by comparing to MySQL tables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Show only new and removed records by comparing to MySQL tables
# 1  
Old 05-30-2012
Show only new and removed records by comparing to MySQL tables

Hello all;

I have been really frustrated with finding the correct perl code (and MySql statements) to accomplish what I thought was straight forward...I have tested I don't know how many different codes\suggestions I found on the net without any success...but anyhow let me explain my plight and what I am looking for...

I have 2 tables (in same db called audit)
Table 1:
Code:
Name: permchk_violations
Fields: `v_node` char(25)
`v_type` char(1)
`v_fd_name` char(100)
`v_path` char(100)
`v_rights` char(9)
`v_owner` char(25)
`v_group` char(25)
`v_size` decimal(15,0)
`v_moddate` char(25)
`v_detected_date` decimal(6,0)
`v_inode` decimal(8,0)

Table 2:
Code:
Name: permchk_violations_tmp
Fields: `t_node` char(25)
`t_type` char(1)
`t_fd_name` char(100)
`t_path` char(100)
`t_rights` char(9)
`t_owner` char(25)
`t_group` char(25)
`t_size` decimal(15,0)
`t_moddate` char(25)
`t_detected_date` decimal(6,0)
`t_inode` decimal(8,0)

So what my code does right now is:
1. copies all records from permchk_violations to permchk_violations_tmp
2. truncates permchk_violations so that it's ready to be populated with more data
3. goes and gets data and populates permchk_violations
4. This is what I need help with - I am suppose to check the newly populated permchk_violations table to the data that was copied to the permchk_violations_tmp table earlier...what I want from this comparison is to do the following:

a. find records that exist in permchk_violations but NOT IN permchk_violations_tmp; write these records to another table (let's call it permchk_violations_new)

b. find records that exist permchk_violations_tmp but NOT IN permchk_violations; write these records to another table (let's call it permchk_violations_removed)

IMPORTANT: I do not care about records that may be "altered" (ie a field changed it's value)

ASSUMPTION: the two tables permchk_violations_new and permchk_violations_removed will have the same field structure as the other two tables I have shown.

So this is my dilemma..hope someone can assist ASAP...I need to get this perl script into production in 1 week's time.

If you need further information please let me know.

Thanks in advance.

Last edited by Franklin52; 05-31-2012 at 03:47 AM.. Reason: Please use code tags for data and code samples
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing two tables

I have defined a set of global variables at the beginning of my script as below: #ideal values export ITEM1=SUCCESS export ITEM2=FAILURE export ITEM3=UNAVAILABLE export ITEM5=FAILURE export ITEM6=SUCCESS now I have a shell script function which returns a value in below format. ITEM1... (1 Reply)
Discussion started by: ctrld
1 Replies

2. Shell Programming and Scripting

UPDATE COmmand post comparing 2 columns in 2 mysql tables

my queryis : select distinct m.name, item_count, item from master m join client p on m.name=p.name where item_count = 1 and item > 1; But how should I update them? i used update statetment : Update from client Set item =1 where m.name=p.name and item_count=1 AND item>1 Is this wrong? (1 Reply)
Discussion started by: siya@
1 Replies

3. Programming

MySQL join four tables!

Hello; I want merge four MySQL tables to get the intersection that have a common field for all of them. Join two tables is fine to me, but my this case is different from common situations and there are not very many discussions about it. Can anybody give me some idea? Thanks a lot! Here is part... (8 Replies)
Discussion started by: yifangt
8 Replies

4. Programming

MySQL: Create a relation between two tables.

Hello everybody, I'm having troubles creating a relation between two tables in a MySQL database. Having two tables, being one which contains users information (username, password, user ID, etc) and the other the one which contains transactions information (operation type, user ID of the user who... (2 Replies)
Discussion started by: semash!
2 Replies

5. Shell Programming and Scripting

Shell script for comparing data of tables

Hi, I have two databases with same tables on different servers.I need to check the data content in each table and if something is missing, should print that. I have a tool which takes the snapshot the table structure,index so on and compares with the other server tables snapshot. Now i need... (1 Reply)
Discussion started by: nessj
1 Replies

6. Web Development

How do you sync tables in mysql between two different servers?

Hi all, I have 2 mysql databases running on two different servers (both can be accessed via ssh to each other). If I have say table ABC on server 1, how can I sync it with table ABC on server 2 if the number of records is different? Both databases are the same structure though server 2 has... (2 Replies)
Discussion started by: muay_tb
2 Replies

7. Shell Programming and Scripting

comparing two tables

I am comparing two table structure in different databases,Put into 2 txt files , when comparing if column sequnce and data type is not matching ,it has to display that info else Table structure is ok. wrote shell script ,its not working .I am getting "Table structure is not ok" even if both... (1 Reply)
Discussion started by: akil
1 Replies
Login or Register to Ask a Question