In MySQL (both instances of phpmyadmin and MySQL workbench) I would like to check if a value exists in a table before I perform any other additional queries to the same table or other tables and below are the sets of queries I have tried but neither are working and both give errors, am new to forming complex queries so kindly ignore any syntax errors I must have made while forming this queries
Query 1
SELECT CASE WHEN ( (SELECT * FROM likes WHERE face_id = 'mm' AND phone_id = 'pp') > 1 )
THEN ( SELECT CASE WHEN ( (SELECT * FROM dislikes WHERE face_id = 'mm' AND phone_id = 'pp') > 1)
THEN ( DELETE FROM likes WHERE face_id = 'mm' AND phone_id = 'pp' )
ELSE SELECT * FROM likes
END
)
ELSE INSERT INTO likes (face_id, phone_id) VALUES ('mm', 'pp')
END
Query 2
IF EXISTS ( SELECT * FROM likes WHERE face_id = 'mm' AND phone_id = 'pp')
IF EXISTS ( SELECT * FROM dislikes WHERE face_id = 'mm' AND phone_id = 'pp')
DELETE FROM likes WHERE face_id = 'mm' AND phone_id = 'pp'
ELSE
SELECT * FROM likes
ELSE/*Else of first IF*/
INSERT INTO likes (face_id, phone_id) VALUES ('mm', 'pp')
END
I got both my choice of queries from here and here
I have 2 tables, likes and dislikes; both tables have three fields id, face_id and phone_id. Data/Values entering into the likes table must not be present in the dislikes table thus if for instance I wish to insert some values into the likes table, I would check if those values are not present in my likes table and then insert my values and return true
but if it is present I would check if somehow it is also present in the dislikes table and if it is, I would delete it from the dislikes table, if not, nothing should happen.