I need to add an if/else stament inside a MySQL query but can’t get it to work.
Below is an example with pseudo-code of what I want to accomplish.
SELECT *
FROM calendar
WHERE calendar.alert = 1
IF calendar.repeat = 0 THEN HAVING calendar.UTC_1 > UNIX_TIMESTAMP();
ELSE "get all records regardless of calendar.repeat value";
END IF;
Any suggestions to make this happen? I couldn’t find the correct syntax for this MySQL IF ELSE.
Thanks for helping!
You can use
IF-ELSEonly inside the body of stored procedure/trigger. You can useIF(condition, value_if_condition_is_true, value_if_condition_is_false)inSELECT, but I preferCASE(you can easily rewrite the query above to