SELECT p.name,vld.qty_available current_stock,AVG(pl.purchase_price) avg_purchase_price,AVG(tsl.unit_price_inc_tax) avg_selling_price FROM products p LEFT JOIN variation_location_details vld ON p.id=vld.product_id LEFT JOIN purchase_lines pl ON p.id=pl.product_id LEFT JOIN transaction_sell_lines tsl ON p.id=tsl.product_id WHERE p.enable_stock=1 GROUP BY p.id,p.name,vld.qty_available ORDER BY avg_purchase_price DESC;