将Sku与产品ID相匹配,并在Magento 1.9中存货

时间:2018-02-15 13:30:33

标签: mysql magento-1.9

我正在尝试显示一个表格:

SKU

product_id

is_in_stock

我得到了这个,它在表格中显示了SKU和产品ID,我想在其中添加is_in_stock,我得到了这个:

SELECT entity_id as product_id, sku FROM catalog_product_entity;

catalog_product_entity表:

enter image description here

我现在需要从表cataloginventory_stock_item添加is_in_stock列,此表包含产品ID列。

enter image description here

我该怎么做?

这是我的输出,我需要从不同的表中添加一列is_in_stock但是我正在努力:

enter image description here

2 个答案:

答案 0 :(得分:1)

请参阅MySQL Join Made Easy以获取以下查询的逻辑:

SELECT A.entity_id as product_id, A.sku, B.is_in_stock 
FROM catalog_product_entity A INNER JOIN cataloginventory_stock_item B
ON A.entity_id=B.product_id;

答案 1 :(得分:1)

找到我正在寻找的查询。如果有人甚至需要它就是这样:

SELECT p.entity_id as product_id, p.sku, c.is_in_stock 
FROM catalog_product_entity as p
INNER JOIN cataloginventory_stock_item as c 
ON p.entity_id = c.product_id