Magento 2 stores data in database tables of customers, orders, products, etc.
The admin may often require to join data of two tables and it can be done using the below solution.
Join 2 tables in Magento 2 while working on product collection data or customers, orders, etc. collection data.
For instance, you need to get the data of all the orders completed through the PayPal payment method, or you need to get the data of customers from a specific country.
All such operations can be done by joining data between 2 tables in Magento 2 as shown below:
Method to Join 2 Tables in Magento 2:
$select = $collection->getSelect(); $select->joinLeft( ["boleta_number" => $collection->getTable("boleta_number")], 'main_table.entity_id = boleta_number.order_id' ); // $collection is an order collection
That’s it.
Also, do share the post with Magento Community via social media.
Thank you.