I have 2 tables. The Data of profit table will come from the bet table. Therefore, automating INSERT to profit table whenever new record got added on bet table will be convenient.
How can I make sure the trigger will insert only data that doesn't exist on the profit table?
Here's what I did so far
DELIMITER $$
DROP TRIGGER IF EXISTS tsuika $$
CREATE TRIGGER keisan BEFORE INSERT ON profitdb
FOR EACH ROW BEGIN
INSERT INTO `profitdb`(`BetID`,`DateTime`, `PlayerID`,
`Profit`,`SubAgentID`,`SubAgentRisk`,`AgentID`,`AgentRisk`)
SELECT `betdb`.`BetID`,`betdb`.`DateTime`,`betdb`.`PlayerID`,
(`BetAmount`-Payout`),`playerdb`.`SubAgentID`,`subagentdb`.`Risk`,
`agentdb`.`AgentID`,`agentdb`.`Risk` FROM `betdb` LEFT JOIN `playerdb` ON
`betdb`.`PlayerID` = `playerdb`.`PlayerID` LEFT JOIN `subagentdb` ON
`subagentdb`.`SubAgentID` = `playerdb`.`SubAgentID` LEFT JOIN `agentdb` ON
`agentdb`.`AgentID` = `playerdb`.`AgentID`
END
$$
DELIMITER;
I referred to this link MySQL trigger On Insert/Update events regarding making triggers with INSERT but still getting this error
#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 'END' at line 5