CoolBrain CoolBrain - 3 months ago 30
SQL Question

SQLite IF ELSE query for Android

I want to do something similar to this:

IF id = 3 AND time = '12/1/2016'
UPDATE visits SET status = 1 WHERE id = 3
ELSE IF id = 3 AND time != '12/1/2016'
DELETE FROM visits WHERE id = 3


I have
id
and
time
, if both matches update a field of row having this
id
, if
id
matches but
time
does not match delete row having this
id
. How would you do that?

Answer

Simple: Use these two statements

UPDATE visits SET status = 1
WHERE id = 3 AND time = '12/1/2016';

DELETE FROM visits
WHERE id = 3 AND time != '12/1/2016';