MySQL Trigger Update with select from another table

后端 未结 2 1825
猫巷女王i
猫巷女王i 2020-12-18 08:26

Just learning about triggers and I\'m created the following trigger;

CREATE TRIGGER `incremental_before_ins_tr` BEFORE INSERT ON incremental`
FOR EACH ROW
BE         


        
2条回答
  •  攒了一身酷
    2020-12-18 08:56

    I've actually managed to solve this myself. Here is the updated code

    CREATE TRIGGER `incremental_before_ins_tr` BEFORE INSERT ON `incremental`
    FOR EACH ROW
    BEGIN
    SET NEW.source = (Select source from crm_record
    where crm_record.msisdn = new.msisdn order by dat DESC limit 1);
    END;
    

    I needed to specify the table name prior to the column value on line 5.

提交回复
热议问题