I am trying to create an Inner join between two tables but am running into a problem with the second table. There is a one to many relationship with the mageuserid in Main table and the entity_id in CCP. I need to only return the store state value in ccp where ccp.attribute_id = x. How would I accomplish that?

        $prefix = Mage::getConfig()->getTablePrefix();
        ->join(array("ccp" => $prefix."customer_entity_varchar"),"ccp.entity_id = main_table.mageuserid",array("store_state" => "value"));

You need get attribute details using Mage::getResourceModel('customer/customer') Model by attribute code .

If your attribute code is store_state the you can get it attribute table name and attribute using below code.

$store_state  = Mage::getResourceModel('customer/customer')->getAttribute('store_state');


$table been taken by static.it can take dynamic by above code


As customer_entity_varchar table has lots of record with different attribute so you need to put attribute id in join query condition

    array('ccp' =>$store_state->getBackend()->getTable()),
    'ccp.entity_id = main_table.mageuserid
    AND ccp.attribute_id = '.(int) $store_state->getAttributeId() . '
| improve this answer | |
  • Makes sense to me! I tried it out and received a Fatal Error for using the joinLeft function Fatal error: Call to undefined method Webkul_Marketplace_Model_Mysql4_Userprofile_Collection::joinLeft() in /public_html/app/code/local/Webkul/Sellers/Block/Sellers.php on line 15 – Kray Apr 8 '15 at 22:06
  • Added ->getSelect() before joinLeft() and it works! Thanks! $collectionfetch->getSelect()->joinLeft( array('ccp' =>$store_state->getBackend()->getTable()), 'ccp.entity_id = main_table.mageuserid AND ccp.attribute_id = '.(int) $store_state->getAttributeId() . ' ', array('store_state'=>'value')); – Kray Apr 8 '15 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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