query for showing columns from various tables, grouping and showing calculated field in each row of the result I am doing a stock management system.
In one table I store items:
ITEM&lt;br&gt;
id_item&lt;br&gt;
item_name&lt;br&gt;

ORDER&lt;br&gt;
id_order&lt;br&gt;
date&lt;br&gt;

ORDER_ITEM&lt;br&gt;
id_ord_item&lt;br&gt;
id_order : foreign key to ORDER id_order primary key&lt;br&gt;
id_item : foreign key to ITEM table.&lt;br&gt;
qty_ordered

STOCK_IN : this table reflects item entries for related item quantities for orders&lt;br&gt;
id_entry&lt;br&gt;
id_ord_item: foreign key to ORDER_ITEM table.&lt;br&gt;
description: optional&lt;br&gt;
in_qty : In of a specific quantity for a specific item in a specific order&lt;br&gt;
in_date: the date where the item quantity arrives to warehouse&lt;br&gt;

Having this structure: I wanted to show a report or query table like this containing the following fields:
item_name&lt;br&gt;,
date (order date)&lt;br&gt;,
description,&lt;br&gt;
qty_ordered,&lt;br&gt;
in_qty,&lt;br&gt;
in_date.&lt;br&gt;
qty_left (calculated field) qty_ordered-sum of in_qty to date&lt;br&gt;

Not sure if I should store the sum of arrive quantities to date in one column and use that to calculate the quantity left then.
Next to those, I want to show a calculated field that in each row that is the pending qnantity left to arrive, which should be the aty_ordered - the sum of arrived item quantity to date (in_qty).
Also, my goal was to show only the items that have a quantity left to arrive for a selected order. Items can come in different shippings, not all quantity ordered at once, and I want to register the date each shipping comes and the quantity of arrival of each item and the date.
I was thinking of not storing calculated values in table fields but I'm not sure if I should.
Also I thought of showing all this in a single query, but I'm not sure if this is possible.
Maybe I should make an agregate query for showing the order and it's item with the item quantity ordered, it's total quantity arrived to date and then in a separate query list all records of the ins of that item and their dates.
I can't figure out a way to do this propery. I thogght I could show a list of items grouped by items inside those orders, and then below list all entries.
I hope someone can though some light on this to me. I'm not sure how to approach this problem.
Basic is that you have all Tables set and also defined the relationship.
Then you add a new query.
Then you pull in all Table that you need, if your relationships are correctly set, all tables should ha a connection.
Now you pull all needed columns into the part below
and add a column that has the difference betwenn qty ordered and inqty

Now you have a corect query to run.
As SQL it looks like
SELECT ITEM.item_name, STOCK_IN.description, ORDER.date_order, ORDER_ITEM.[qty_ordered]
, STOCK_IN.in_qty, STOCK_IN.in_date, [qty_ordered]-[in_qty] AS qty_left
FROM ([ORDER] 
      INNER JOIN (ITEM 
       INNER JOIN ORDER_ITEM ON ITEM.id_item = ORDER_ITEM.id_item) ON ORDER.id_order = ORDER_ITEM.id_order) 
       INNER JOIN STOCK_IN ON ORDER_ITEM.id_ord_item = STOCK_IN.id_ord_item;

For your query to have the complete quantity for all orders
SELECT ITEM.item_name, STOCK_IN.description, ORDER.date_order, ORDER_ITEM.[qty_ordered], STOCK_IN.in_qty, STOCK_IN.in_date, [Sum1] AS qty_left
FROM 
    ([ORDER] INNER JOIN (
                                           ( ITEM INNER JOIN (SELECT ORDER_ITEM.id_item
                                                                       ,SUM( [qty_ordered]-[in_qty]) AS Sum1
                                                                       FROM ([ORDER] INNER JOIN ORDER_ITEM ON ORDER.id_order = ORDER_ITEM.id_order) INNER JOIN STOCK_IN ON ORDER_ITEM.id_ord_item = STOCK_IN.id_ord_item
                                                                       GROUP BY ORDER_ITEM.id_item) qtysum ON qtysum.id_item = ITEM.id_item
                                           )
INNER JOIN ORDER_ITEM ON ITEM.id_item = ORDER_ITEM.id_item
) ON ORDER.id_order = ORDER_ITEM.id_order) 
INNER JOIN STOCK_IN ON ORDER_ITEM.id_ord_item = STOCK_IN.id_ord_item;

Result: