DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`receipt_beforeInsert` BEFORE INSERT ON `receipt` FOR EACH ROW BEGIN DECLARE vIsAutoConciliated BOOLEAN; IF NEW.isConciliate = FALSE THEN SELECT isAutoConciliated INTO vIsAutoConciliated FROM accounting a JOIN accountingType at2 ON at2.id = a.accountingTypeFk WHERE a.id = NEW.bankFk; SET NEW.isConciliate = vIsAutoConciliated; END IF; END$$ DELIMITER ;