I had created a stored procedure in MySQL. It has to get the values for 5 different columns and perform calculations based on the input params and update the calculated value to the table. I was able to create the stored procedure, but when executing it, it throws an error stating that 'MYSQL said: #1172 - Result consisted of more than one row.'
Below is my stored procedure
DELIMITER $$
CREATE DEFINER=`andrew`@`localhost` PROCEDURE `st_update_userpoints`(
in point int,
in gold int,
in silver int,
in bronze int,
in userId int)
BEGIN
DECLARE _gold int default 0;
DECLARE _silver int default 0;
DECLARE _bronze int default 0;
DECLARE _points int default 0;
DECLARE _score int default 0;
select `goldMedal`,`silverMedal`,`bronzeMedal`,`totalPoints`,`score` into @_gold,@_silver,@_bronze,@_points,@_score from `userpoints` where `userId`=userId;
set _gold:=(@_gold+gold);
set _silver:=(@_silver+silver);
set _bronze:=(@_bronze+bronze);
set _points:=(@_points+points);
set _score = (@_gold*5)+(@_silver+3)+(@_bronze)+(@_points);
update `userpoints` set `goldMedal`=@_gold, `silverMedal`=@_silver, `bronzeMedal`=@_bronze, `totalPoints`=@_points,
`score`=@_score where `userId`=userId;
END$$
DELIMITER ;
select ... fromuserpoints` whereuserId=userId;`. Are you sure this SQL query can only produce 1 row at most?