Tag Archives: magento join 3 tables

Magento join multiple tables


Magento join mulitple tables : You can join multiple tables in magento as below.


Magento join multiple tables Syntax

Following syntax is used for joining multiple tables in magento :

//load collection 
$collection = Mage::getModel('module/model_name')->getCollection();
$collection->getSelect()->join(Mage::getConfig()->getTablePrefix().'table2_to_be_joined','main_table.table_field ='.Mage::getConfig()->getTablePrefix().'table2_to_be_joined.table2_field',array('field_name'));
//join with 3rd table
$collection->getSelect()->join(Mage::getConfig()->getTablePrefix().'table3_to_be_joined','main_table.table_field ='.Mage::getConfig()->getTablePrefix().'table3_to_be_joined.table3_field',array('field_name'));