SELECT p.name,vld.qty_available current_stock,v.default_purchase_price unit_cost,vld.qty_available*v.default_purchase_price carrying_cost FROM products p JOIN variations v ON p.id=v.product_id LEFT JOIN variation_location_details vld ON p.id=vld.product_id WHERE p.enable_stock=1 ORDER BY carrying_cost DESC;