Tutorialsplane

Magento 2 Join 3 Tables


Magento 2 Join 3 Tables collection –We can join more than two table collections in Magento 2 which will return data collectively from three tables using join. You can also add conditions to the collection as per your need. Here in this tutorial, we are going to explain how to join 3 tables in Magento 2.


Magento 2 Join 3 Tables Colleaction Example

Here is an example of 3 table joins-

Example:

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
$collection = $objectManager->get('Magento\Sales\Model\Order')->getCollection();
$collection->getSelect()
->join( array('order_item'=> 'sales_order_item'),
'order_item.order_id = main_table.entity_id', array('order_item.sku'))
->join( array('quote'=> 'quote'),
'quote.quote_id = main_table.quote_id', array('quote.grand_total'));