Stock balance query
Since the actual database doesn't get updated and I'm not a sql expert, can I get assistance to get a list of products remaining balance by updating the sql below.Can't get the list to show stock with a 0 balance.
SELECT ProductStock,((SELECT ProductStock - coalesce(sum(DetailQuantity),0) AS NumLeft
FROM (orderdetails join orders on((orders.OrderID = orderdetails.DetailOrderID)))
WHERE ((orderdetails.DetailProductID = ProductID) and (orders.OrderDate > ProductUpdateDate)))) AS NumLeft,(SELECT CouponProductID FROM couponproducts WHERE couponproducts.ProductID = products.ProductID AND couponID = 41 LIMIT 1) AS CouponProductID,coalesce((select productoptions.GroupingID FROM productoptions where productoptions.ProductID = products.ProductID limit 1),products.ProductID) AS GroupingID FROM products WHERE ProductUnlimited = 0 AND ((SELECT ProductStock - coalesce(sum(DetailQuantity),0) AS NumLeft FROM (orderdetails join orders on((orders.OrderID = orderdetails.DetailOrderID))) WHERE ((orderdetails.DetailProductID = ProductID) and (orders.OrderDate > ProductUpdateDate))))