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

MySQL JOIN e COUNT em uma única consulta

SELECT o.id, o.f_name, o.l_name, COUNT(od.id), COALESCE(SUM(od.qty), 0)
FROM orders o
LEFT JOIN order_details od ON o.id = od.order_id
GROUP BY o.id, o.f_name, o.l_name