title: How atomic are SQL transactions really in MySQL?
body: <p>I wonder — if I have have an SQL transaction where in one statement I do a select query, and then in a later statement an update query, is it guaranteed that nothing has been changed by outside factors in between the two?</p>
  
  <ul>
  <li><p>So I select a number of rows ⟵ in the transaction</p></li>
  <li><p>Another procedure changes one of the rows ⟵ outside the transaction</p></li>
  <li><p>Than I want to do the update ⟵ in the transaction</p></li>
  </ul>
  
  <p>So can this happen? I know the total transaction either happens or it doesn't, but are all individual statements in 1 transaction also executed as 1 atomic unit where nothing can happen in between two different statements? Or is the only way to ensure that the database is locked in between the two statements by setting a manual table lock?</p>
  
  <p>This problem is about this by the way: I transfer money from one user (the buyer) to another (the seller). However, the buyer already deposited money when placing the buy order. Now he may cancel this buy order at any moment. I will then give him back the deposited money. So now it can happen that I'm in the process of transferring the deposited money from the buyer to the seller, while the buyer cancels his order, and I give him back his money. So now the money is given to the buyer, AND to the seller. This requires some high level isolation right?</p>