For MySQL, If I stored the userid and a token in the user
table and only allows to insert record in another table if the supplied userid and token matches.I've tried
INSERT INTO product(description)
VALUES('123')
WHERE EXISTS
(SELECT 1 FROM users where userid='myuserid' AND token='ABCD')
The following SQL statement produces error "check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE EXISTS (SELECT 1 FROM users where userid='29')'"
However for update I can update successfully with
UPDATE product
SET description='123'
WHERE EXISTS
(SELECT 1 FROM users where userid='myuserid' AND token='ABCD')
Can any experts please help to advise. I need the most efficient way to verify the user token is correct before doing the insert.