Get the sum by comparing between two tables

Posted by Ismail Gunes on Stack Overflow See other posts from Stack Overflow or by Ismail Gunes
Published on 2013-11-11T21:51:36Z Indexed on 2013/11/11 21:52 UTC
Read the original article Hit count: 262

Filed under:

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.status>0 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.

© Stack Overflow or respective owner

Related posts about mysql