I have a query am having issues with,
SELECT id, name, cc, total FROM goods gd
LEFT JOIN (SELECT count(*) as cc, status, pid, SUM(number) as total FROM prices)pr
ON pr.pid = gd.id AND pr.status = 0 WHERE gd.id=20
When I run this query on local server if fetches correctly but on my remote server the cc and total is returned null.
Please any idea on the cause?
Note: if I removed count(*) and SUM(number) it returns multiple rows, I want the Left join to get me total matches and sum of number in the second table.
Read more here: MySQL Left Join with SUM and Where clause returning Null