title: MYSQL item transaction
body: <p>I'm using MysQL, and I have a table called <code>abilities</code>, where each row is a unique ability that the player owns. Each row holds the data:</p>
  
  <pre><code>{
   uuid (unique id of owner of the ability),
   ability_uuid (unique id of ability itself),
   ability_id (type of ability)
  }
  </code></pre>
  
  <p>The player trades the ability with another player, and I want it to update the owner <code>uuid</code> of the ability to the player they are trading with, all in 1 query. 
  Here is what I have:</p>
  
  <pre><code>UPDATE abilities AS abilities1
  INNER JOIN abilities AS abilities2 ON
    ( abilities1.uuid = 'player1_uuid' AND abilities2.uuid = 'player2_uuid' )
  SET 
    abilities1.uuid = abilities2.uuid,
    abilities2.uuid = abilities1.uuid
  ;
  </code></pre>
  
  <p>This works, and will swap every ability that the player owns with the other player. The problem is that let's say the player loses ownership of one of the abilities, the trade will still process all of the other abilities except the one that was traded.</p>
  
  <p>So, for example, if player1 trades <code>ability1</code> and <code>ability2</code> with player2 for their <code>ability3</code> and <code>ability4</code>, and it turns out that player1 no longer owns <code>ability1</code> for some reason, it will still trade <code>ability2</code> for <code>ability3</code> and <code>ability4</code>, so player2 gets screwed.</p>
  
  <p>How can I fix this and make it so MySQL checks that they own the abilities that the server thinks they do?</p>