MYSQL IF not exists insert ELSE delete
I'm trying to do that:
IF (EXISTS(SELECT * FROM `favorite_pic` WHERE `Pic` = 1 AND `User` = 1)) THEN
DELETE FROM `favorite_pic` WHERE `Pic` = 1 AND `User` = 1
ELSE
INSERT INTO `favorite_pic`(`User`, `Pic`) VALUES(1, 1)
END IF;
Is that possible? I mean, if there is a record delete it, if there is not,
insert.
No comments:
Post a Comment