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... 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. 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! 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? 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
Archived
This topic is now archived and is closed to further replies.