title: Query limit in oracle database
body: <p>I am trying to create query with kind of limit. </p>
  
  <p><code>SELECT * FROM ALARMS WHERE OBJECT_ID=0 AND TIMESTAMP&lt;=1525677504171 AND ROWNUM&lt;=51 ORDER BY TIMESTAMP DESC</code></p>
  
  <p>I use rownum but first it makes a limit and then it select ordered by. However I need to order first and then limit. I found here <a href="https://stackoverflow.com/questions/470542/how-do-i-limit-the-number-of-rows-returned-by-an-oracle-query-after-ordering?utm_medium=organic&amp;utm_source=google_rich_qa&amp;utm_campaign=google_rich_qa">enter link description here</a> that I should use <code>FETCH FIRST 51 ROWS ONLY</code>. Unfortunately it doesn't work.</p>
  
  <pre><code>SELECT * FROM ALARMS WHERE OBJECT_ID=0 AND TIMESTAMP&lt;=1525677504171 ORDER BY TIMESTAMP DESC FETCH FIRST 51 ROWS ONLY;
  </code></pre>
  
  <p>It throws me following error:</p>
  
  <pre><code>SQL Error [933] [42000]: ORA-00933: SQL command not properly ended
  
  oracle.jdbc.OracleDatabaseException: ORA-00933: SQL command not properly ended
  </code></pre>