allspiritseve Posted December 12, 2007 Share Posted December 12, 2007 I would like to use a REPLACE query using two separate text fields as keys. If both keys match, the record is replaced, while if one or the other matches, but not both, a new record is inserted. I am not sure exactly what my db structure needs to look like, as I've only ever used an int pkey with auto-increment. I am using MySQL 5.0.45 on a LAMP server. Thanks, Cory Quote Link to comment https://forums.phpfreaks.com/topic/81388-solved-replace-using-two-keys/ Share on other sites More sharing options...
fenway Posted December 12, 2007 Share Posted December 12, 2007 Is your UNIQUE index multi-column? Quote Link to comment https://forums.phpfreaks.com/topic/81388-solved-replace-using-two-keys/#findComment-413141 Share on other sites More sharing options...
allspiritseve Posted December 12, 2007 Author Share Posted December 12, 2007 Yes, though I wasn't sure exactly if that was what I needed. Even with the multi-column index, a REPLACE query still inserts when both columns are specified. Is there something else I need to do? Quote Link to comment https://forums.phpfreaks.com/topic/81388-solved-replace-using-two-keys/#findComment-413178 Share on other sites More sharing options...
fenway Posted December 13, 2007 Share Posted December 13, 2007 Hmmm... that's unusual.. could you post your table structure so I can test it? Quote Link to comment https://forums.phpfreaks.com/topic/81388-solved-replace-using-two-keys/#findComment-413477 Share on other sites More sharing options...
allspiritseve Posted December 13, 2007 Author Share Posted December 13, 2007 You know, I figured it out. I had a multi column INDEX instead of UNIQUE. Quote Link to comment https://forums.phpfreaks.com/topic/81388-solved-replace-using-two-keys/#findComment-413603 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.