Hello,
I am using Libreoffice base 6.3.5.2 (x64) on Windows 10 with embedded database and have setup a small base with the idea to create invoices with a customer table and items table etc…
So here is one where I can’t find a solution by myself (newbie in learning process)
I have 3 table to define a current stock situation:
- ITEMS
- Items_In which is stock as it comes in
- SOLD which are the ones that are being invoiced and therefore get out from stock
I have found a simple way to deduct the sold items from the items in (in stock), the problem is that it will only display the items which have show data in SOLD. I would like to display the items which had no sales as current stock.
To better explain, we have say 10 items with stock and 2 sold, the below SQL will only show data of the 2 Items sold.
Assuming that this is due to the missing data (or NULL) on SOLD table, I have been trying various options using COALESCE and I cannot get to show all Items which have stock, still only the ones which show sales.
To be clear I would like to have a query which show all stock from all items, even if that is zero
My SQL is:
SELECT “ITEMS”.“SKU”, COALESCE ( “Items_IN”.“QTY”, 0 ) - COALESCE ( “SOLD”.“QTY”, 0 ) AS “STOCK_CURRENT” FROM “SOLD”, “ITEMS”, “Items_IN” WHERE “SOLD”.“ITEM_ID” = “ITEMS”.“ITEM_ID” AND “ITEMS”.“ITEM_ID” = “Items_IN”.“ITEM_ID”
If somebody has an idea or direction to follow as it seems that I am missing something in the procedure.
Thank you for your time.