title: Database Deadlock in SELECT FOR UPDATE
body: <p>I'm getting deadlock intermittently in my application. My application has 1 table e.g EMPLOYEE (ID (PK), NAME, SAL) and there are 2 sessions.</p>
  
  <p>Session 1: </p>
  
  <pre><code>SELECT ID, NAME, SAL FROM EMPLOYEE WHERE SAL = (SELECT MIN(SAL) FROM 
  EMPLOYEE) FOR UPDATE
  Let say the query return EMPLOYEE ROW having ID=2
  then application does some processing like rs.updateInt(ID_SAL, 10);
  </code></pre>
  
  <p>Session 2: (for other business logic)</p>
  
  <pre><code>SELECT ID, NAME, SAL FROM EMPLOYEE WHERE ID=2 FOR UPDATE.
  </code></pre>
  
  <p>So, in the application both sessions try to update the same row (in example row with ID=2) Such situation is expected and hence I thought SELECT .. FOR UPDATE will help.</p>
  
  <p>Am I doing something wrong? I'm assuming that SELECT FOR UPDATE will lock the row and when other session will try to update the same row, it will wait until session 1 completes execution.</p>