Mysql
 sql >> Base de données >  >> RDS >> Mysql

Forcer toutes les lignes de la première table d'une jointure

SELECT p.*
     , SUM(mp.quantity) AS qty
FROM products p
  LEFT JOIN machine_products mp
    ON mp.product_id = p.product_id
    AND mp.machine_id = m              --- this condition moved from WHERE to ON
WHERE p.category_id = c
GROUP BY p.product_id