sqldatabasems-accessentity-relationshiperd

How to show the same field value from another entity attributes


enter image description here

How can i show the same value of attribute from Item_Stock under entity PurchaseOrder and Warehouse ?

To be more specific, i need to do a calculation from warehouse that when Item_Stock is taken by PurchaseOrder then the Item_Stock value at Warehouse will be minus according to how many total quantity of the Purchase_Quantity.


Solution

  • By using a SQL query, the following should show which products that has the same "item_Stock" value on both PurchaseOrder table or Warehouse table.

    select 
      p.product_id, 
      po.item_Stock as PurchaseOrder_item_Stock,
      po.item_Stock as Warehouse_item_Stock,
    from product p
    join PurchaseOrder po on p.product_id = po.product_id
    join Warehouse w on p.product_id = w.product_id
    where po.item_Stock = w.item_Stock
    

    the field's value is being shown side by side as different columns for each entity.