Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Forçando todas as linhas da primeira tabela de uma junção

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