I'm trying to create a trigger to insert into a new table using values from two different tables (I'm using MySQL 5.5.27).
I get a syntax error when I try this but cannot see where the error is.
DECLARE _Token VARCHAR(255);
SELECT token INTO _Token FROM appusers ON username = NEW.username;
INSERT INTO queue (token, message) VALUES (_Token, NEW.milestone);
My assumption is that it doesn't like the DECLARE because when I use the following I get message that _Token is an undeclared variable.
SELECT token INTO _Token FROM appusers ON username = NEW.username;
INSERT INTO queue (token, message) VALUES (_Token, NEW.milestone);
Try do it with a single insert statement
INSERT INTO queue (token, message)
SELECT token, NEW.milestone
FROM appusers
WHERE username = NEW.username;
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.