Skip to content

Magento 2 : Create a JOIN

I am trying to fetch manufacturer attribute value using SKU.

Here is my query which works fine.

SELECT nametable.value,
catalog_product_entity.sku
FROM catalog_product_entity_varchar AS nametable
LEFT JOIN catalog_product_entity
ON nametable.entity_id = catalog_product_entity.entity_id
WHERE nametable.attribute_id = (SELECT attribute_id
FROM eav_attribute
WHERE entity_type_id = 4 and store_id = 0
AND attribute_code LIKE ‘manufacturer’)

I am trying to convert it to magento code like below in my this existing code

protected function _initSelect()
{
    $this->addFilterToMap('created_at', 'main_table.created_at');
    parent::_initSelect();
    $this->getSelect()->joinLeft(
        ['secondTable' => $this->getTable('mst_rma_rma')],
        'main_table.rma_id = secondTable.rma_id',
        );
    return $this; 
}

Is their any way to do it ?