Hi i am trying to create a procedure that gets the ansID as a param and updates the "score" field in both the User table and Answer Table.
DELIMITER $$
CREATE PROCEDURE UpVoteAnswer(IN _ansID INT)
BEGIN
SET @_userID = SELECT user_id from Answers where id = _ansID;
UPDATE Answers SET score = score + 1 where id = _ansID;
UPDATE Users SET score = score + 1 where id = @_userID;
END
$$
DELIMITER ;
Error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT user_id from Answers where id = _ansID;
UPDATE Answers SET score = score' at line 3
Use either
SET @_userID = (SELECT user_id from Answers where id = _ansID);
or
SELECT user_id from Answers where id = _ansID INTO @_userID;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.