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 for diafol

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.