Thursday, August 27, 2015

MySQL case in where clause example


SELECT * FROM `table_users` WHERE (CASE WHEN (id > 7 AND id < 13) THEN online=1 ELSE TRUE END) AND `table_users`.`status`=1


This mean return online=1 (which can be TRUE or FALSE) in case id <13 and id > 1, or always return TRUE otherwise.

No comments:

Post a Comment