I have two tables:
students (student_id, id_carrera, nro_doc ... rterc, eterc) PK (student_id, id_carrera).
debts (rterc, eterc, date_of_voice, number_of_voice, amount, expiration ...) The table does not have debts.
The field eterc is equal to the document number.
To get rid of the student's debts I use a sp like this:
CREATE DEFINER='root'@'localhost' PROCEDURE 'ALU_DEUDAS'(
IN p_alumno varchar(50),
IN p_rterc char(2),
IN p_eterc char(15)
)
BEGIN
if p_rterc != '' and p_eterc != '' then
SELECT d.*
FROM camp_deuda as d
INNER JOIN camp_alumnos as a
ON a.calu_rterc = d.rterc and a.calu_eterc = d.eterc
WHERE a.calu_id_alumno = p_alumno AND d.rterc = p_rterc AND d.eterc = p_eterc;
end if;
END
It works perfectly, the problem is when the student is enrolled in several races. He repeats the invoices according to the careers that the student has.
How can I solve it? I thought about doing a select distinct nro_factura
.
I do not know what you think. Thank you very much