yangkai9999 Posted November 30, 2009 Share Posted November 30, 2009 Hello,I'm a new one to use MySQL. I have a table say tab1. It includes some records, and the primary Key is ID. Now I have another table say tab2. The two tables' structures are identical. The tab2 has some records which existed in tab1 and some new records.I need to update tab1 records if the one existing from tab2 and insert the new records from tab2.How to write a single SQL to perform the task?Thank you, Link to comment Share on other sites More sharing options...
justsomeguy Posted November 30, 2009 Share Posted November 30, 2009 Is it an option to delete everything from the one table and copy the other to it? If the tables have identical columns that's easy to do. Link to comment Share on other sites More sharing options...
yangkai9999 Posted November 30, 2009 Author Share Posted November 30, 2009 Is it an option to delete everything from the one table and copy the other to it? If the tables have identical columns that's easy to do.I couldn't delete everything from tab1 since I need to keep some records which existing in it. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 30, 2009 Share Posted November 30, 2009 If you want to do everything with a single query you'll probably have to use this:http://dev.mysql.com/doc/refman/5.0/en/ins...-duplicate.html Link to comment Share on other sites More sharing options...
yangkai9999 Posted November 30, 2009 Author Share Posted November 30, 2009 If you want to do everything with a single query you'll probably have to use this:http://dev.mysql.com/doc/refman/5.0/en/ins...-duplicate.html thank you, this is what I need. Link to comment Share on other sites More sharing options...
Bling125 Posted December 12, 2009 Share Posted December 12, 2009 If you want to do everything with a single query you'll probably have to use this:http://dev.mysql.com/doc/refman/5.0/en/ins...-duplicate.html Great find this also help my friend with the same error that this guy had. Cheers Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.