Arty Ziff Posted April 29, 2011 Share Posted April 29, 2011 I'd like to add rows to a table, but only if a certain (varchar) col value does not already exist. I know I could make that col unique... Is there a way to form the INSERT query to insure uniqueness? I don't want to rely on MySQL returning an error... Quote Link to comment https://forums.phpfreaks.com/topic/235055-insuring-row-with-unique-col/ Share on other sites More sharing options...
requinix Posted April 29, 2011 Share Posted April 29, 2011 How about a REPLACE (=DELETE+INSERT)? You would have to make the column unique - which you should anyway, if the column really is supposed to be unique. Quote Link to comment https://forums.phpfreaks.com/topic/235055-insuring-row-with-unique-col/#findComment-1208010 Share on other sites More sharing options...
Arty Ziff Posted April 29, 2011 Author Share Posted April 29, 2011 Oooooo! I've never heard of REPLACE, but I like it! Quote Link to comment https://forums.phpfreaks.com/topic/235055-insuring-row-with-unique-col/#findComment-1208025 Share on other sites More sharing options...
fenway Posted May 1, 2011 Share Posted May 1, 2011 INSERT IGNORE? Quote Link to comment https://forums.phpfreaks.com/topic/235055-insuring-row-with-unique-col/#findComment-1209134 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.