RichardG
RichardG

Reputation: 455

MySQL syntactical error

I'm trying to execute the following code on my hosts mysqladmin page.

CREATE PROCEDURE `follow`(IN in_follower INT(11), IN in_followee VARCHAR(45))
BEGIN
INSERT INTO follower (follower_id, followee_id) VALUES (in_follower, (SELECT user_id FROM user WHERE username = in_followee));
END

The error I get is :

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

Why is this error happening here? When I used that code in MySQL Workbench it ran fine.

Upvotes: 1

Views: 590

Answers (1)

John Woo
John Woo

Reputation: 263803

Try thisone,

DELIMITER $$
CREATE PROCEDURE `follow` 
(
    IN in_follower INT (11) ,
    IN in_followee VARCHAR(45)
)
BEGIN
        INSERT INTO follower ( follower_id , followee_id )
        SELECT in_follower AS follower_id, user_id
        FROM user
        WHERE username = in_followee;
END$$
DELIMITER ;

Upvotes: 2

Related Questions