This question already has an answer here:

I have developed Magento module that shows out of stock products in last of catalog page list and I test it in my test website and it works correctly but in other websites (Magento I got following error

ERROR : a:5:{i:0;s:64:"You cannot define a correlation name 'sorting_t1' more than once";i:1;s:6125:"#0 /home/resellern/domains/mysite.com/public_html/lib/Varien/Db/Select.php(281): Zend_Db_Select->_join('left join', Array, 'e.entity_id=sor...', Array, NULL)

1 /home/resellern/domains/mysite.com/public_html/app/code/core/Zend/Db/Select.php(373): Varien_Db_Select->_join('left join', Array, 'e.entity_id=sor...', Array, NULL)

2 /home/resellern/domains/mysite.com/public_html/app/code/core/Mage/Eav/Model/Entity/Attribute/Source/Table.php(122): Zend_Db_Select->joinLeft(Array, 'e.entity_id=sor...', Array)

3 /home/resellern/domains/mysite.com/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php(1595):#2#3

and this is my code that run in observrer.php

 $toolbar = Mage::getBlockSingleton('catalog/product_list_toolbar');
    if ($toolbar) {
        $products = $observer->getEvent()->getCollection();

        $stockId = Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID;
        $websiteId = Mage::app()->getStore($products->getStoreId())->getWebsiteId();

            array('_inv' => $products->getResource()->getTable('cataloginventory/stock_status')),
            "_inv.product_id = e.entity_id and _inv.website_id=$websiteId and _inv.stock_id=$stockId",
        $products->addExpressionAttributeToSelect('in_stock', 'IFNULL(_inv.stock_status,0)', array());

        $products->getSelect()->order('in_stock DESC');

        if ($toolbar->getCurrentOrder()) {
            $products->addAttributeToSort($toolbar->getCurrentOrder(), $toolbar->getCurrentDirection());

    return $this;

I say again this code work in my test and other websites but it doesn't work in the specific website and got an error.

marked as duplicate by sv3n, Piyush, Sukumar Gorai, Manashvi Birla, Priyank Oct 3 '18 at 13:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Hey go through below link this might help you: You cannot define a correlation name '*_idx' more than once

If you find this answer helpful please mark it as solution or upvote thanks.

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