SQL:无法加入这两个表(EAV Architechture,Magento)

时间:2015-01-08 22:15:31

标签: mysql sql magento

以下查询为我提供了entity_id和name列

SELECT e.entity_id, eav.value AS name
FROM catalog_product_entity e
JOIN catalog_product_entity_varchar eav
  ON e.entity_id = eav.entity_id
JOIN eav_attribute ea
  ON eav.attribute_id = ea.attribute_id
  WHERE ea.attribute_code = 'name'

以下查询为我提供了entity_id和price列

SELECT e.entity_id, eav.value AS price
FROM catalog_product_entity e
JOIN catalog_product_entity_decimal eav
  ON e.entity_id = eav.entity_id
JOIN eav_attribute ea
  ON eav.attribute_id = ea.attribute_id
  WHERE ea.attribute_code = 'price'

我无法加入这两个,一次获取entity_id,名称和价格列,有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

尝试:

SELECT e.entity_id, eav.value AS name, eav2.value as price
  FROM catalog_product_entity e
  JOIN catalog_product_entity_varchar eav
    ON e.entity_id = eav.entity_id
  JOIN eav_attribute ea
    ON eav.attribute_id = ea.attribute_id
  JOIN catalog_product_entity_decimal eav2
    ON e.entity_id = eav2.entity_id
  JOIN eav_attribute ea2
    ON eav2.attribute_id = ea2.attribute_id
 WHERE ea.attribute_code = 'name'
   and ea2.attribute_code = 'price'