I have these tables, payroll, deductions, bonuses, advances, employee, and what I want is to add the total bonus, total deductions, total advances, then show this data, and with this calculate the total salary and group it by idEmpleado, I've done it with inner join but I multiply the result almost 60 times, I do not know why.
THIS IS THE CODE I HAVE
SELECT emp.idEmpleado,
per.Pnombre PrimerNombre, per.Snombre SegundoNombre, per.Papellido PrimerApellido, per.Sapellido SegundoApellido,
p.fechaPago, p.montoPago,
de.estado EstadoDeduccion, de.fecha FechaDeduccion, de.primerMonto PrimerMontoDeduccion,
bo.estado EstadoBono, bo.pmonto PrimerMontoBono,
an.estado EstadoAnticipo, an.fecha FechaAnticipo, an.primerMonto PmontoAnticipo,
((((SUM(p.montoPago)) + (SUM(bo.pmonto))) - (SUM(de.primerMonto))) - (SUM(an.primerMonto))) total
FROM planilla p
INNER JOIN deducciones de
ON (de.idPlanilla = p.idPlanilla)
INNER JOIN bonos bo
ON (bo.idPlanilla = p.idPlanilla)
INNER JOIN anticipos an
ON (an.idPlanilla = p.idPlanilla)
INNER JOIN empleado emp
ON (emp.idEmpleado = an.idEmpleado)
LEFT JOIN persona per
ON (per.idPersona = emp.idPersona)
group BY emp.idEmpleado