title: SOQL Query in loop
body: <p>The following APEX code:</p>
  
  <pre><code>for (List&lt;MyObject__c&gt; list : [select id,some_fields from MyObject__c]) {
    for (MyObject__c item : list) {
      //do stuff
    }
  }
  </code></pre>
  
  <p>Is a standard pattern for processing large quantitues of data - it will automatically break up a large result set into chucks of 200 records, so each List will contain 200 objects.</p>
  
  <p>Is there any difference between the above approach, and below:</p>
  
  <pre><code>for (List&lt;MyObject__c&gt; list : Database.query('select...')) {
    for (MyObject__c item : list) {
      //do stuff
    }
  }
  </code></pre>
  
  <p>used when the SOQL needs to by dynamic?</p>
  
  <p>I have been told that the 2nd approach is losing data, but I'm not sure of  the details, and the challenge is to work out why, and to prevent data loss.</p>