Carrie1956 Posted November 11, 2012 Share Posted November 11, 2012 I have a mysql table with the name of the fruit as primary key. If I'm given a new table with NEW names of fruits, I want those to go into my table. However, if the primary key (the fruit) already exists in my first table, I don't want it updated. For example: Table 1: apple red olive green Table 2: olive black lemon yellow Since table 1 already has an olive, I don't want the olive from table 2 inserted (even though it's a different color), but I want the lemon inserted into table 1 What is the correct mysql syntax, please? Thank you!! Quote Link to comment https://forums.phpfreaks.com/topic/270575-mysql-update-question/ Share on other sites More sharing options...
Barand Posted November 12, 2012 Share Posted November 12, 2012 (edited) Check out "INSERT IGNORE" in the manual http://dev.mysql.com/doc/refman/5.6/en/insert-select.html Edited November 12, 2012 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/270575-mysql-update-question/#findComment-1391755 Share on other sites More sharing options...
Carrie1956 Posted November 12, 2012 Author Share Posted November 12, 2012 Hi, thank you for your quick response! Would you mind explaining the stuff I need to type before the "insert ignore" part? I know it will be select into or union or join or something. I have been trying to research this online but I guess I'm feeling kind of dumb today :-) Would it be something like insert ignore into Original_Table (select * from New_Table where New_Table.fruit != Original_Table.fruit); Thank you!! Quote Link to comment https://forums.phpfreaks.com/topic/270575-mysql-update-question/#findComment-1391762 Share on other sites More sharing options...
Barand Posted November 12, 2012 Share Posted November 12, 2012 (edited) I've no idea what your column names are so INSERT IGNORE INTO original_table (a, B) SELECT c, d FROM new_table Edited November 12, 2012 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/270575-mysql-update-question/#findComment-1391769 Share on other sites More sharing options...
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.