In MySQL server, I want to do a trigger that checks when a row inserted, if the row has the previous value in column A than the previous row, it should delete it.

Im a little forgetful on how to check this correctly so if someone could lend a hand, thank you.

Best I got:

USE database;
DELIMITER $$
CREATE TRIGGER checkrow BEFORE INSERT ON table6 FOR EACH ROW
if inserted.column1 == select column1 from table6 order by id desc limit 1 then
delete inserted.column1

But after that...no clue what to do.

USE database;
DELIMITER $$
CREATE TRIGGER checkrow BEFORE INSERT ON table6 FOR EACH ROW
if inserted.sha1(column1) == select sha1(column1) from table6 order by id desc limit 1 then
delete inserted.column1;
end if

I don't think you can delete the record to be inserted. There must be a way to cancel it, perhaps by throwing an exception (signal).

Well how is the best way I can do that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.