Here is a sql query:
SELECT SUM(a.quantity)-SUM(IF(ISNULL(b.quantity),0,b.quantity)) AS stock
FROM wp_wpsp_inventory_items a, wp_wpsp_assigned_inventory b
WHERE a.master_id='9' AND
(CASE WHEN ISNULL(b.quantity)
THEN '' ELSE a.master_id=b.master_id
END)
There are two tables a and b. Table a stores all the inflows and the table b stores all outflows. Here I'm trying to calculate the stock by subtracting outflows from inflows. But there are situations when there is no entry of an Item in Table b is such case the query returns NULL. I tried using IF()and ISNULL() but nothing worked. Please help
NULL, but an empty result set instead. So what is the real question? Do you ask about how to handle that case in your application?master_id=9but in some cases, my 2nd Tablebhas no entry formaster_id=9