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();
["boleta_number" => $collection->getTable("boleta_number")],
'main_table.entity_id = boleta_number.order_id'
// $collection is an order collection
Any doubts about a method to join two tables in Magento 2 can be mentioned in the Comments section below. I’d be happy to help.
Also, do share the post with Magento Community via social media.
Get Weekly Updates
Never miss Magento tips, tricks, tutorials, and news.
Thank you for subscribing.
Something went wrong.