Sometimes you want to modernize the column in the table from another table’s column in Magento 2.
Power Your Online Business With An Advanced And Secure Magento 2 Solution!!!
You can use the “update from select “function to do it to update the column in the fields.
The following example for the resource model:
Steps to Modernize the Magento 2 table
$connection = $this->getConnection(); $select = $connection->select() ->from( ['main_table' => $this->getResource()->getMainTable()] ) ->joinLeft(['join_table'=>$this->getTable('join_table')], "main_table.id = join_table.id", array('name' => 'name')); $query = $connection->updateFromSelect( $select, ['main_table' => $this->getResource()->getMainTable()] ); $connection->query($query);
This is the query after the code is contribute
UPDATE `maintable` AS `maintable` INNER JOIN `maintable` LEFT JOIN `'join_table'` AS `'join_table'` ON main_table.id = 'join_table'.id SET `'main_table'`.`name` = `'join_table'`.`name`
I hope the following steps are the smallest process for you to modernize the column in the table from another table in Magento 2.
Leave a Reply