Hello! I need to update a field in a table with the total number of occurrences of the table B When I run the command below, it works. SELECT COUNT(P.cod_patient) FROM HOSP.PATIENT AS P When I put in the structure below, it does not error, but does not update the field. What might be happening? BEGIN DECLARE total_pacient INT; SET total_pacient = (SELECT COUNT(P.cod_pacient) FROM HOSP.PATIENT AS P); UPDATE HOSP.ESTATISTIC SET total_patient_bd = total_patient; END Thank you very much
Hi, PopSSiCle. I made a mistake in typing the primary keys. The correct is cod_patient. I'm trying here, I've read the documentation and could certify that the command is correct. Do I need to do some setting on my MySql? I'm really lost. Thank you for your interest in helping me.
This might sound silly, but make sure the database user has write permissions. Secondly, although the return type of count() is INT, but make sure that total_patient variable is getting the returned value correctly. I once ended up in a similar problem and the solution was to get the row[1] in returned result instead of row[0]. Print the value of total_patient before running the update query to see what's in it. Good luck