title: How to select first 'N' records from a database containing million records?
body: <p>I have an oracle database populated with million records. I am trying to write a SQL query that returns the first 'N" sorted records ( say 100 records) from the database based on certain condition.</p>
  
  <pre><code>SELECT * 
  FROM myTable 
  Where SIZE &gt; 2000 
  ORDER BY NAME DESC
  </code></pre>
  
  <p>Then programmatically select first N records.</p>
  
  <p>The problem with this approach is :</p>
  
  <ul>
  <li>The query results into half million
  records and "ORDER BY NAME" causes
  all the records to be sorted on NAME in the descending order. This sorting is taking lot of time. (nearly 30-40 seconds. If I omit ORDER BY, it takes only 1 second).</li>
  <li>After the sort I am interested in
  only first N (100) records. So the sorting of complete records is not useful.</li>
  </ul>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Is it possible to specify the 'N' in
  query itself? ( so that sort applies to only N records and query becomes faster).</li>
  <li>Any better way in SQL to improve the query to sort
  only N elements and return in quick
  time.</li>
  </ol>