Here's my statement:
SELECT
a.size AS 'size_id',
b.size,
a.stock,
a.id AS 'stock_id',
IFNULL(c.quantity,0) as 'cart_qty'
FROM
stock a
JOIN
sizes b ON a.size = b.id
LEFT JOIN
cart_items c ON a.id = c.stock_id
WHERE
a.product_id = '{$product['id']}'
AND
c.cart_id = '$cart_id'
AND
a.stock > 0
ORDER BY
b.display_order
In the above, $cart_id might be blank, or it might have no matches in the 'cart_items' table. How do I rephrase the above so that if there are no matches in cart_items, I still get the results from stock that match product_id? But if there are matches in cart_items then I get the additional column (cart_qty)?
AND c.cart_id = $cart_id