How To Use Magento Join Query In Collection?

There are circumstances when you need to use join query for fetching the specific results as required which must be done using the below mentioned method.

Magento Join Query Syntax :

$collection = Mage::getModel('Module_name/Model_name')->getCollection();
$collection->getSelect()->join( array('table_alias'=> 'table_name'),
 'condition', array('columns_name1'));

Magento join query in collection Example:-

Here we are going to explain how to load order invoices in Magento.

$collection = Mage::getModel('sales/order')->getCollection();
$collection->getSelect()->join( array('order_item'=> sales_flat_order_item), 
'order_item.order_id = main_table.entity_id',
 array('order_item.sku'));

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *