Can I delete rows in a table when calling a trigger on it?
such as:
insert into table1 (col1, col2, col3) values (val1, val2, val3);
CREATE DEFINER=`root`@`localhost` TRIGGER `db`.`trig_name` BEFORE INSERT ON `table1` FOR EACH ROW
BEGIN
if (new.val1 > (select val1 from table1 where val2 = new.val2 limit 1))
delete from table1 where val2 = new.val2;
end if;
END
This is so that I only keep the maximum val1 per val2.
I have done this in PostgreSQL but I cannot find a way to accomplish in MySQL.