0

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);
0

1 Answer 1

2

Try do it with a single insert statement

INSERT INTO queue (token, message)
SELECT token, NEW.milestone
  FROM appusers 
 WHERE username = NEW.username;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.