Mysql
 sql >> Database >  >> RDS >> Mysql

MySQL unisce solo le righe selezionate

Puoi fare

SELECT SUM(netto)
FROM   invoices
       LEFT JOIN invoices_elements
         ON invoices_elements_code_invoices_id = invoices_id
            AND invoices_elements_enable = 1
WHERE  invoices_enable = 1
GROUP  BY invoices_elements_code_invoices_id  

Nota la restrizione invoices_elements_enable = 1 è in ON clausola per evitare di convertire la query in un inner join .