I currently have two tables, one is products and the other is options (colour, size, etc). If no options are specified for the product, it puts the stock against the product table Otherwise it will put the stock against the option table
Tables look a bit like this:
Product table: productid, name, sku, stock
Option table: optionid, productid, sku, stock
I want to pull the data from both tables, and add up the "stock"
So far I have this:
SELECT `product`.`productid`, `product`.`name`, `product`.`sku`,
( SUM(`product`.`stock`) ) + ( SUM(`option`.`stock`) ) AS `stock`
FROM `product`
LEFT JOIN `option` ON `product`.`productid` = `option`.`productid`
GROUP BY `productid`
Which displays the data how I want but the issue is with the stock. For a product that has options specified, it adds them up nicely. If the product doesn't have an option, it just displays "NULL"
Results 