The following query generates a random string of 20 characters:
SELECT LEFT(MD5(RAND()), 20);
My aim is to insert this into the token field of the users_address field when a new row is added. I created the following trigger:
BEGIN
INSERT INTO users_address (token) VALUES (SELECT LEFT(MD5(RAND()), 20));
END
which returns the error "You have an error in your SQL syntax; check the manual…". If I replace the SELECT statement with an actual string, the trigger is created so the issue seems to be the SELECT. What do I need to do to change to make it work?
>Solution :
SELECT is not needed in VALUES Clause :
INSERT INTO users_address (token) VALUES (LEFT(MD5(RAND()), 20));