The following query only work when I have a reference in the table wm_purchased_products.purchased_article_id but when this is empty mysql_num_rows return 0
The query is:
SELECT (SUM(wm_products_quantities.new_quantity) - SUM(wm_purchased_products.purchased_article_total) ) AS stock_restante,
wm_products_wall.nombre,
wm_products_wall.detalles,
wm_products_wall.price,
wm_products_wall.image_full,
wm_products_wall.fecha,
wm_products_wall.article_hashid
FROM wm_products_wall,
wm_products_quantities,
wm_purchased_products
WHERE wm_products_wall.categoria = '$new_rquery_xp'
AND wm_products_wall.article_hashid = wm_products_quantities.hashid_ref
AND wm_products_wall.article_hashid = wm_purchased_products.purchased_article_id
GROUP BY wm_products_wall.article_hashid
ORDER BY stock_restante ASC
How to build this query to work when I have no record in the table wm_purchased_products.purchased_article_id
Your code
FROM wm_products_wall, wm_products_quantities, wm_purchased_productsmeans all three table are INNER JOIN with each other.(that is, each and every row in the first table is joined to each and every row in the second table and so on.)You can let wm_products_wall LEFT JOIN with wm_purchased_products, so do wm_purchased_products.