After searching around, I still haven't found a solution. So I thought I would post it here. Any help would be greatly appreciated.

When I go to filter one of the columns it redirects me to dashboard. After that when I click on sales -> orders it loads the following error:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'store_id' in where clause is ambiguous, query was: SELECT COUNT(*) FROM mg_sales_flat_order_grid AS main_table INNER JOIN mg_sales_flat_order AS order ON order.entity_id=main_table.entity_id WHERE (store_id = '1')

  • Which version of Magento? Any custom columns in grid has been added?
    – rafal-kos
    Commented Aug 11, 2016 at 14:45
  • and not that I'm aware of I didn't build the site. Columns that exist are: Order, Purchased From (Store), Purchased On, Bill to Name, Deliver to Name, G.T. (Base), G.T. (Purchased), Voucher Code, Billing Postcode, Delivery Postcode, Status
    – Hayden
    Commented Aug 11, 2016 at 14:52

1 Answer 1


Try to use below code just before the $this->setCollection($collection);

$collection->addFilterToMap('store_id', 'main_table.store_id');

Another solution used in some default Magento modules is

if (!Mage::app()->isSingleStoreMode()) {
            $this->addColumn('store_id', array(
                'header'    => Mage::helper('sales')->__('Purchased From (Store)'),
                'index'     => 'store_id',
                'type'      => 'store',
                'store_view'=> true,
                'display_deleted' => true,
                'filter_index' => 'main_table.store_id',
  • I have tried doing both of those fixes but nothing works. I have even tried applying the same filter_index but for every column and also addfiltertomap for all of the columns. Just to confirm I have to edit the /app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php file? Another thing I have noticed is that the voucher code column is there but it doesn't exist in the code. I'm starting to think now that it might be an extension trying to edit the grid view. Also is there anything I need to do after I have saved changes to the code, I have been flushing the cache.
    – Hayden
    Commented Aug 11, 2016 at 15:38
  • See in code for this kind of string Mage_Adminhtml_Block_Sales_Order_Grid.php to see if something is not overriding the class. You should also place changed file in app/code/local to avoid problems with magento updated in future. After change there is no need to do any cache cleaning as I know.
    – rafal-kos
    Commented Aug 11, 2016 at 20:15
  • I think we are on to something here. I have just checked the development site and there is no includes/src folder where Mage_Adminhtml_Block_Sales_Order_Grid.php is. On the main site there is with lots of files in there. This could be the fix, I will update this post if it works by adding it in.
    – Hayden
    Commented Aug 12, 2016 at 7:53
  • Ok so I added the file into the includes/src/ folder and edited it with code above but still no fix. I am now slightly concerned why there is no src folder here on the dev site but there is on the main site. Thank you for all your help so far. It would be a huge relief to resolve this one.
    – Hayden
    Commented Aug 12, 2016 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.