INSERT … ON DUPLICATE KEY UPDATE with WHERE?
问题 I'm doing a INSERT ... ON DUPLICATE KEY UPDATE but I need the update part to be conditional, only doing the update if some extra condition has changed. However, WHERE is not allowed on this UPDATE . Is there any workaround for this? I can't do combinations of INSERT/UPDATE/SELECT since this needs to work over a replication. 回答1: I suggest you to use IF() to do that. Refer: conditional-duplicate-key-updates-with-mysql INSERT INTO daily_events (created_on, last_event_id, last_event_created_at)