0

hi i'm trying to update two different tables with one trigger but i keep getting syntax error and i'm not sure what i'm doing wrong

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use

near 'UPDATE specialitys s

JOIN speciality_objects o ON s.id = o.speciality' at line 2

triggers works fine if i just update one table but i cant put them both in one trigger

here is my trigger

  DELIMITER $$
  CREATE TRIGGER after_user_type_or_status_change
  AFTER UPDATE
  ON users
  FOR EACH ROW

  BEGIN
  UPDATE stats s 

  SET

    ee_counter =
      CASE 
        WHEN  NEW.type= 1 THEN ee_counter + 1
        WHEN  NEW.type= 3  && OLD.type = 2 THEN ee_counter + 1
        WHEN  OLD.type= 1  && NEW.type != 3  THEN ee_counter - 1
        ELSE ee_counter 
      END ,

    er_counter =
      CASE 
        WHEN  NEW.type= 2  THEN er_counter + 1
        WHEN  NEW.type= 3  && OLD.type = 1 THEN er_counter + 1
        WHEN  OLD.type= 2  && NEW.type != 3  THEN er_counter - 1
        ELSE er_counter 
      END 

  WHERE
    s.id = 1;
END $$

BEGIN
UPDATE specialitys sp 

JOIN speciality_objects o
      ON sp.id = o.speciality_id

    JOIN users u
      ON o.user_id = u.id

 SET
    counter =
      CASE 
        WHEN  NEW.status = 1 THEN counter + 1
         ELSE counter 
      END 

  WHERE
    sp.id = o.speciality_id ;

END $$

DELIMITER ;

1 Answer 1

0

The END $$ in the middle is ending the trigger definition. Remove it and the following BEGIN.

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.