Ver originalSelect sbc.fecha,sbc.producto,sum(sbc.ingreso),sum(sbc.salida)FROM (SELECT fecha,producto,cantidad as ingreso,0 as salida FROM ingreso UNION ALL SELECT fecha,producto,0 as ingreso,cantidad as salida FROM salida) as sbcGROUP BY sbc.fecha,sbc.producto