I have a small problem I just can not get a grip on...
I have a table (inventory) that I would like to pull data from,
When a new product is added to the database, rows are added to the inventory table, but because there is no history for these products there is no entries in the inventory_history table. The statement I have (second one below) works fine for data in the inventory_history table but I can not get it to read the new data from the inventory table.
I need to add the results of the first statement to the results of the second statement. There is a cross over of data, the first statement will show some results that are not needed because there are entries for the same sku in the inventory_history table. I basically need to pull the new sku's from the inventory table that do not yet have entries in the inventory_history table and add them to the result of the second statement. The column inventory.quantity_on_hand is a little misleading, to get true quantity on hand, you must use SUM(inventory_history.remaining) see second statement. But because there is no history inventory.quantity_on_hand has a 0
`vendor_id` = 17
AND `quantity_on_hand` <= `minimum_stock_level`
GROUP BY sku
,SUM(remaining) AS "Qty On Hand"
ON inventory_history.sku = inventory.sku
WHERE inventory_history.store_id = 4
AND inventory.vendor_id = 10
GROUP BY sku
How can I combine these statements?