'MYSQL TRIGGER (BEFORE INSERT) gives me NULL
please I have a probleme with MYSQL TRIGGER :
CREATE TRIGGER BEFORE INSERT ON `table_A`
FOR EACH ROW
SET NEW.name = (SELECT `table_B`.`name` FROM `table_A` INNER JOIN `table_B`
ON `table_A`.`table_B_id` = `table_B`.`id` WHERE `table_A`.`id` = NEW.id);
So I need that col name in table_A fill from table_B using the NEW.id in join. it's like the NEW.id is NULL so that col fill with NULL any ideas and thank you in advance
Solution 1:[1]
There seems to be no reason to include table_A in the select or WHERE table_A.id = NEW.id)
SET NEW.name = (SELECT `table_B`.`name` FROM `table_B`
ON new.`table_B_id` = `table_B`.`id` );
If this doesn't work for you add sample data and expected output as text to the question
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | P.Salmon |
