I am trying to join two tables like below

    $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();

    $collection = $objectManager->get('Advance\Module\Model\Method')
    ->getCollection()->addFieldToFilter('stores', ['finset' => $store_id]);

    $collection->getSelect()->joinLeft( ['shippingrate'=> 'shippingrate'], 
    'shippingrate.method_id = main_table.method_id', ['main_table.method_id']);

This is returning all data from two tables. I could not get specific columns from the end result.

  • Try this answer magento.stackexchange.com/a/166292/84221 – Rahul Barot May 3 at 4:24
  • Try with shippingrate table's column in array like $collection->getSelect()->joinLeft( ['shippingrate'=> 'shippingrate'], 'shippingrate.method_id = main_table.method_id', ['shippingrate.column_name']); – Mital Shah May 3 at 6:49

You can refer to this example of mine:

protected function filterOrder($payment_method)
        $this->sales_order_table = ""main_table"";
        $this->sales_order_payment_table = $this->getTable(""sales_order_payment"");
            ->join(array('payment' =>$this->sales_order_payment_table), $this->sales_order_table . '.entity_id= payment.parent_id',
                array('payment_method' => 'payment.method',
                    'order_id' => $this->sales_order_table.'.entity_id'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.