I'm trying to join two tables but it's returning wrong result could you please suggest me how to write it.

Data: From my custom table(product_id,email,id) have Product_id.

Expecting Result : join the two tables (custom_table and catalog_product_entity) to display the Product Name, Sku and Email_id

Could you please tell me how to write it?

2 Answers 2


This works for me. The only change between Magento 1 and Magento 2 is how to get the table name:

   'main_table.admin_user_id = admin.user_id',

I will do something like this:

    $connection = $this->_objectManager->create('\Magento\Framework\App\ResourceConnection');
    $conn = $connection->getConnection();
    $select = $conn->select()
            ['main_table' => 'catalog_product_entity'],
            ['custom_table' => 'custom_table'],
            'main_table.entity_id = custom_table.product_id'

    $data = $conn->fetchAll($select);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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