in the table 'chat':

I would like to delete messages if they have been deleted by both sender an recipient. If, however, a user is the first to delete a message, this should just be recorded under "deleted_by" with his user id (until the second user also deletes the message).
For message #3 and user #1 my query would look like so:
IF
(SELECT deleted_by from chat WHERE id=3) <> '1' AND (SELECT deleted_by from chat WHERE id=3) <> '0' THEN
DELETE FROM chat WHERE id=3
ELSE
UPDATE chat
SET deleted_by=1
WHERE id=3
END IF
This should delete message #3, but instead I get an error. Can you help me make my according SQLfiddle work?
Thank you!