I am new to magento 2, And want to join 4 tables.

TABLE 1) market_p_userdata (columns -> seller_id, image)
TABLE 2) market_product (columns -> seller_id, magepro_id)
TABLE 3) catalog_category_product (columns -> product_id)
TABLE 4) customer_entity (columns-> entity_id)

TABLE 3) product_id (primary key) which is as a foriegn key in TABLE 2) named as magepro_id,

TABLE 4) enity_id(primary key) which is foreign key in TABLE 3) AND 2) named as seller_id,

TABLE 2) seller_id(primary key) which is foreign key in TABLE 1) named as seller_id,

I want to get Image of seller and name of seller, I have searched many links, But still I am not getting how to create join.

2 Answers 2


Here is the simple example how you can join multiple tables in Magento

   protected $_productCollectionFactory;  

      public function __construct(

            \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory

        ) {

            $this->_productloader = $_productCollectionFactory;


    public getmyCollection(){
    $collection = $this->productCollectionFactory->create();
                'e.entity_id = table1join.product_id',
                'e.entity_id = table1join.product_id',
            'e.entity_id = table2join.product_id',
  • Thanks, I want to join 4 table not 2 tables, Kindly answer for 4 tables. I have searched for 2 tables as I have mentioned in question. Jan 20, 2017 at 5:49
  • @Khushbu_sipl These are 3 tables first was the collection two are attached with join if you want to add another join just add another like i do for fourth Jan 20, 2017 at 5:58
  • okay, I am trying will let you know when its done. Thanks :) Jan 20, 2017 at 6:39

Joining a Table in a collection is so simple in magento2:

            'main_table.id = secondTable.entity_id','*');
            'main_table.id = thirdTable.entity_id', '*');


You can Add numerous Table like this.. Hope it will help All. :)

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.