skip to Main Content

I am trying to get a table that displays:

SKU

product_id

is_in_stock

I got this which displays SKU and Product ID in a table and I want to add is_in_stock to it, I got this:

SELECT entity_id as product_id, sku FROM catalog_product_entity;

catalog_product_entity table:

enter image description here

I need to add is_in_stock column now from table cataloginventory_stock_item, this table holds the product ID column.

enter image description here

How can I do that?

This is my output, I need to add a column is_in_stock to it from different table but am struggling:

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    Found the query I was looking for. It was this if anyone even needs it:

    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
    

  2. See MySQL Join Made Easy to get the logic of the query below:

    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;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search