title: In magento, update customer entity if customer has at least one order
body: <p>I have created a custom attribute is_buyer for user which will be set to 1 after order post event.</p>
  
  <p>Now I want to set 'is_buyer' to 1 for old users which have at least one order. </p>
  
  <p>I can do this using foreach loop but I want to do this with a single query. </p>
  
  <p>Any body knows how to write query for mentioned task using magento.</p>
  
  <p>I have already written one time script using loop. </p>
  
  <pre><code>    &lt;?php
      set_time_limit(0);
      $customers = Mage::getModel('customer/customer')
              -&gt;getCollection()
              -&gt;addAttributeToSelect('entity_id')
              -&gt;addAttributeToFilter(array(array('attribute' =&gt; 'is_buyer', 'null' =&gt; true)), '', 'left');
  
      $orders = Mage::getSingleton('sales/order')-&gt;getCollection()
          -&gt;addAttributeToSelect('customer_id');
  
      foreach ($customers as $customer) {   
          $orders-&gt;addFieldToFilter('customer_id', $customer-&gt;getId());
          if ($orders-&gt;count() &gt; 0) {
              $customer-&gt;setData('is_buyer', 1);        
          } else {
               $customer-&gt;setData('is_buyer', 0);     
          }
          $customer-&gt;save();
  }
  </code></pre>