I have two identical fields table, say "tb1" and "tb2".
"tb1" has records:
1
2
3
4

"tb2" has records:
1
4
5
6

Now how can I compare this two tables and insert differential from "tb1" into "tb2", so "tb2" will be:
1
2
3
4
5
6

Is there any easy way to do it? Thanks for any advice.

Let's say you have the field, id, as the only field in both tables. The query

INSERT INTO tb2 
    SELECT id FROM tb1 
     WHERE id NOT IN (SELECT id FROM tb2)  

will do what you want.

Member Avatar

This (or the other one!) is a duplicate post. How about we carry on here. OK - deleted duplicate. For the record, here was my effort...

INSERT IGNORE INTO table2 (field1, field2)  
    SELECT field1, field2 FROM table1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.