Get the sum by comparing between two tables
- by Ismail Gunes
I have to tables ProdBiscuit As tb and StockData As sd , I have to get the sum of the quantity in StockData (quantite) with the condition of if (sd.status0 AND sd.prodid = tb.id AND sd.matcuisine = 3)
Here is my sql query
SELECT tb.id, tb.nom, tb.proddate, tb.qty, tb.stockrecno
FROM ProdBiscuit AS tb
JOIN
(SELECT id, prodid, matcuisine, status, SUM(quantite) AS rq FROM StockData) AS sd
ON (tb.id = sd.prodid AND sd.status > 0 AND sd.matcuisine = 3) LIMIT 25 OFFSET @Myid
This gives me no rows at all ?
There is only 3 rows in ProdBiscuit and 11 rows in Stockdata and there is only 2 rows in StockData good with the condition.
And as shown in the picture there is only two rows which give the condition.
What is wrong in my query ?
PS: The green lines on the image shows the condition in my query.