0

I have 3 tables: the first one gets all records to the t1 table, the second one is where my whitelist entries are, and the third one is for making some decision in the future regarding to t2. I need to create after insert trigger an update via my third table. the steps :

  1. some value come into the tables called "t1"
  2. need to check if the value is in "t2"
  3. if the value is in t2 so go to t3 and do something, if the value is not in t2 so go to t3 and do something else.
  4. but the value will always need to enter t1.

This is my code and it does not work, I don't know how to apply it I've tried many options already.

CREATE TRIGGER check_whitelist AFTER INSERT ON t1
FOR EACH ROW
SELECT
IF(IFNULL(new.name=(
    select name From t2 where (t2.name = new.name),
    UPDATE t3 SET option1 =0 ,
    UPDATE t3 SET option2 =1
)))

Please help me with writing this code.

0

1 Answer 1

1

You can't put an UPDATE query inside a SELECT query. Use an IF() expression in the value that you're assigning to option1.

FOR EACH ROW
UPDATE t3 SET option1 = IF(new.name = (SELECT name FROM t2 WHERE t2.plate = new.name),
                           0, 1)
Sign up to request clarification or add additional context in comments.

1 Comment

@a.artur Please see: How to accept an answer for closure. You get points for it as well. Thanks :)

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.