Get VARCHAR Attribute Value for SKU by MySQL Query in Magento 2.1.x

Had to query the Database directly for a Attribute Value of a SKU – which was quicker than writing an entire module to pick out a single value.

Replace SKU_NAME with the SKU you’re attempting to find, and the ATTR_NAME is the Attribute Code.


SELECT
    cvar.value_id AS catalog_product_entity_varchar_id,
    attr.attribute_code AS attribute_code,
    prd.sku,
    cvar.value AS twinhead_id,
    prd.type_id,
    prd.updated_at,
    prd.entity_id AS product_id
FROM
    eemagento.catalog_product_entity_varchar cvar
JOIN
    eemagento.catalog_product_entity prd ON (prd.row_id = cvar.row_id)
JOIN
    eav_attribute attr ON ( attr.attribute_id = cvar.attribute_id )
WHERE
    prd.sku = 'SKU_NAME' AND attr.attribute_code = 'ATTR_NAME'