title: SQL query for second largest value with a where condition
body: <p>I have a table with step id and resident id. I wanted to write a query find the second largest step id for a particular resident. </p>
  
  <p>The query using max in the google examples doesn't have the where clause. 
  Tried this:</p>
  
  <pre><code>SELECT DISTINCT(step_action_id) 
  FROM step_table where resident_id =219 
  ORDER BY step_action_id DESC limit 2,1;
  </code></pre>
  
  <p>Table:</p>
  
  <pre><code>Step_Action_id REsident_id
  800               218
  801               218
  911               218
  857               218       
  856               219
  858               219
  </code></pre>
  
  <p>Result am expecting is 856. but i am getting the below error,</p>
  
  <pre><code>Error: ILLEGAL USE OF KEYWORD LIMIT.  TOKEN SKIP OPTIMIZE FOR FETCH , EXCEPT MINUS UNION &lt;END-OF-STATEMENT&gt; WAS EXPECTED. SQLCODE=-199, SQLSTATE=42601, DRIVER=3.59.81
  SQLState:  42601
  ErrorCode: -199
  Error: THE CURSOR SQL_CURLH200C1 IS NOT IN A PREPARED STATE. SQLCODE=-514, SQLSTATE=26501, DRIVER=3.59.81
  SQLState:  26501
  ErrorCode: -
  </code></pre>