Hello. I ran into the problem of deleting rows by an attached request, or to be more precise, two deletions are performed in one store, and most of all, I think that the first is performed without the subquery, and the second one does not have the necessary value.

CREATE DEFINER=`root`@`localhost` PROCEDURE `RemoveStudent`( -- Add the parameters for the stored procedure here id CHAR(36) ) BEGIN IF (SELECT Count(IdStudent) FROM GroupeStudent WHERE GroupeStudent.IdStudent = id) = 0 THEN call RemoveCourseGroupe((SELECT GroupeStudent.IdGroupe FROM GroupeStudent WHERE GroupeStudent.IdStudent = id)); END IF; DELETE FROM Student WHERE Student.Id = id; END 
  • What error message is displayed? Or just not deleted? - cheops
  • No, the order of operations cannot be violated. Check your RamoveCourseGroupe procedure for what it performs what is expected and that it receives the expected value at the input - Mike

1 answer 1

The whole problem was in logic. It was necessary to rewrite the request itself.

 BEGIN IF ((SELECT Count(gs.IdStudent) FROM GroupeStudent INNER JOIN GroupeStudent as gs ON gs.IdStudent = id) = 1) THEN call RemoveCourseGroupe((SELECT GroupeStudent.IdGroupe FROM GroupeStudent WHERE GroupeStudent.IdStudent = id)); END IF; DELETE FROM Student WHERE Student.Id = id; END 
  • Please tell me, is this the answer to your own question? - Nicolas Chabanovsky
  • Yes, I simply did not log in initially :) - Igor Klimenko