3

I want to access the product names by query database using product ID. How can I achieve it?

  • u want sql query or Magento default way – Arshad Muhammad Dec 21 '16 at 11:32
  • i want sql query . I know the default way. – Nitin Pawar Dec 21 '16 at 11:33
  • why do you want using SQL query? – chirag Dec 21 '16 at 11:42
  • I want to access the product names outside magento without using api. – Nitin Pawar Dec 21 '16 at 11:43
10

Magento uses an EAV table structure for products. Names are stored in catalog_product_entity_varchar. If you have the product ID X, you can query this table directly:

SELECT entity_id, value, store_id FROM catalog_product_entity_varchar
  WHERE entity_id = X AND attribute_id = (
    SELECT attribute_id FROM eav_attribute
    WHERE entity_type_id=4 AND attribute_code='name'
  )

The subquery determines the attribute id for "name", entity_type_id 4 is always the type ID for products.

Note that in a multistore setup you might get multiple values per product. Pay attention to the "store_id" column. "0" stands for the default value.

1

Use below query to find name from product_id

SELECT value FROM catalog_product_entity_varchar WHERE entity_id=2 AND (attribute_id IN(SELECT attribute_id FROM eav_attribute WHERE attribute_code = "name" AND entity_type_id = 4))

Change entity_id=2 as per your product id

1

If your product's id is 1234:

select value from catalog_product_entity_varchar left join eav_attribute on
    eav_attribute.attribute_id = catalog_product_entity_varchar.attribute_id
where
    eav_attribute.attribute_code='name' and 
    catalog_product_entity_varchar.entity_id=1234
  • there is no row_id column, use entity_id instead of row_id. – chirag Dec 21 '16 at 12:04
  • In Magento 2 you have row_id – Phoenix128_RiccardoT Dec 21 '16 at 12:21
  • what? can you share screenshot of your database table? – chirag Dec 21 '16 at 12:21
  • Magento EE has row_id. – nikola99 Feb 1 '17 at 0:03
0

Or you can try this also,for single record, X is your product_id you have to replace it by your own product id.

SELECT DISTINCT value FROM catalog_product_entity_varchar WHERE entity_id=X AND (attribute_id IN(SELECT attribute_id FROM eav_attribute WHERE  attribute_code = "name" AND entity_type_id = 4))

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.