title: MEMSQL - UPSERT IF (Versioning of records)
body: <p>I have a stream of events of user creation and user updates. </p>
  
  <p>Each event contains the event type (Creation Or Update) and the entire user entity i.e. UserID, Username, Email Etc.. <strong>plus a Version number</strong> indicating the user version such that creation will be version 0, 1st update version 1 etc..</p>
  
  <p>The events are not necessarily ordered so I might get Version 2 before Version 1
  <strong>AND</strong> also they can be processed in parallel so that while i'm trying to persist version 1 the other events stream processor(s) is trying to persist in parallel version 2.</p>
  
  <p>I want to perform <strong>UPSERT</strong> with atomic condition (IF) such that successfull update will be only if VERSION_IN_DB &lt; NEW_VERSION_IM_TRYING_TO_UPDATE.
  If the DB doesn't contain any version just insert the user record. (atomic as well)</p>
  
  <p>This all should make sure, that only the latest version of the user will be persisted in all cases - multi-threaded, unordered event stream etc..</p>
  
  <p>Any idea how can I do it with MEMSQL?</p>