I have three tables item, store and stock_movement. The stock movement has the fields id, item_id, store_id and quantity. I would like to create a view showing the sum of the quantities of each item in each store. If there is no stock_movement entry for an item in a store, the quantity should be zero.
I came up with the following query:
SELECT item.*, store.id, SUM(s.quantity) AS quantity
FROM item, store 
LEFT JOIN stock_movement s ON s.item_id = item.id AND store.id = s.store_id
GROUP BY store.id, item.id;
I get the following error:
Error Code: 1054 Unknown column 'item.id' in 'on clause'
If I switch the query to use FROM store, item the unknown column changes:
Error Code: 1054 Unknown column 'store.id' in 'on clause'
This answer to use INNER JOIN won't work for me since there are some items and stores without corresponding stock_movement entries i.e the result is missing a few rows.
So is there a way to do this cross join?
 
     
    