Table1 - col_name col_city col_tid

Table 2 - col_id col_city

In Magento2 i want col_name,col_city from Table1 And col_id from Table2 Using Join Query And col_city is in both table so i just want col_city from Table1.

i already tried with below join query


                array('tbl2' => $this->getTable('Table2')),
                'main_table.col_tid = tbl2.col_id'

but it returns both tables col_city column , so i just want col_city only from Table1

so please tell me how i can do this in Magento2

1 Answer 1


TO short out this issue if you have to use an alise column name for Table2 's column col_city.

If you want to get the first table column name then you can use main_table.col_city at join query.

But when if you want to get data using php collection object then you use an alise column name for Table2 's column col_city.

Join Query:

                array('tbl2' => $this->getTable('Table2')),
                'main_table.col_tid = tbl2.col_id',
                    'tbltwocity' => 'tbl2.col_city',


$collection if collection object then you can second table's city value by

foreach($collection as $each)
  • But how can you please share sample code Jul 11, 2019 at 7:34
  • sure. i will share shortly
    – Amit Bera
    Jul 11, 2019 at 8:00

Your Answer

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

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