2

I want join from Table 1 -> Table 2 has id = custom_id

Then join from Table 2 -> Table 3 has Table2.id = Table3.id

And will get table1.id if eligible

My Table

enter image description here

Ex : Table 1 -> Table 2

Table1.id = Table2.custom_id => choose two field

enter image description here

Table 2.id = Table3.id => choose one field

enter image description here

And get data Table 1

enter image description here

1

Well I don't understand your question as much, but from the title of the question I could answer you that. You want to join 3 tables and choose 2 columns of table2, 1 column from table3

So here: Assume the $collection is the resource model collection of the table 1.

We have

        $collection->getSelect()
            ->joinLeft(
                ['table2' => $collection->getTable('table2')],
                'main_table.id = table2.custom_id',
                [
                    'table2_id' => 'table2.id',
                    'table2_custom_id' => 'table2.custom_id'
                ]
            )
            ->joinLeft(
                ['table3' => $collection->getTable('table3')],
                'table2.id = table3.id',
                [
                    'table3_custom_field' => 'table3.custom_field'
                ]
            );

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.