yangkai9999 0 Posted November 30, 2009 Report 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, Quote Link to post Share on other sites
justsomeguy 1,135 Posted November 30, 2009 Report 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. Quote Link to post Share on other sites
yangkai9999 0 Posted November 30, 2009 Author Report 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. Quote Link to post Share on other sites
justsomeguy 1,135 Posted November 30, 2009 Report 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 Quote Link to post Share on other sites
yangkai9999 0 Posted November 30, 2009 Author Report 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. Quote Link to post Share on other sites
Bling125 0 Posted December 12, 2009 Report 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 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.