title: Using column aliases in Sales Order Grid field
body: <p>I'm trying to add two fields (<code>Shipping Postcode</code> and <code>Billing Postcod</code>) to Magento 1.7CE's backend Sales grid. </p>
  
  <p>I'm doing this by overriding <code>Mage_Adminhtml_Block_Sales_Order_Grid::setCollection(...)</code> to join the table with <code>sales/order_address</code>.</p>
  
  <pre><code>public function setCollection($collection){
      parent::setCollection($collection);
      $collection-&gt;getSelect()-&gt;join(
          array('address_shipping' =&gt; $collection-&gt;getTable("sales/order_address")),
          'main_table.entity_id = address_shipping.parent_id AND address_shipping.address_type = "shipping"',
          array('postcode')
      );
      $collection-&gt;getSelect()-&gt;join(
          array('address_billing' =&gt; $collection-&gt;getTable("sales/order_address")),
          'main_table.entity_id = address_billing.parent_id AND address_billing.address_type = "billing"',
          array('postcode')
      );
  }
  </code></pre>
  
  <p>And <code>Mage_Adminhtml_Block_Sales_Order_Grid::_prepareColumns(...)</code> to add the columns to Sales Grid.</p>
  
  <pre><code>protected function _prepareColumns(){
      $this-&gt;addColumn('shipping_postcode', array(
          'header' =&gt; Mage::helper('sales')-&gt;__('Shipping Postcode'),
          'index' =&gt; 'postcode',
      ));
      $this-&gt;addColumn('billing_postcode', array(
          'header' =&gt; Mage::helper('sales')-&gt;__('Billing Postcode'),
          'index' =&gt; 'postcode',
      ));
      return parent::_prepareColumns();
  }
  </code></pre>
  
  <p>The issue is that both times I need to select <code>postcode</code> field from <code>sales/order_address</code> table which results in SQL error</p>
  
  <pre><code>SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'postcode' in order clause is ambiguous
  </code></pre>
  
  <p>I have tried to use MySQL's <code>AS</code> alias to differentiate between two postcodes, by modifying <code>setCollection(...)</code> to pass <code>array('shipping_postcode'=&gt;'postcode')</code> and <code>array('billing_postcode'=&gt;'postcode')</code> as well as changing <code>_prepareColumns(...)</code> to say <code>'index' =&gt; 'shipping_postcode'</code> and <code>'index' =&gt; 'billing_postcode'</code>. This resulted in another SQL error</p>
  
  <pre><code>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'shipping_postcode' in 'where clause'
  </code></pre>
  
  <p>How can I achieve having both columns in the Sales Grid? </p>