Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL IF Condition in Where Clause

Is it possible to decide by IF Condition which Where Clause I want to choose.

Something like:

IF(DATE_FORMAT(DATE(akDate), '%a')='SAT', USE WHERECLAUSE1, USE WHERECLAUSE2)
like image 765
Jings Avatar asked Dec 13 '22 07:12

Jings


1 Answers

This is the case you can still write using rather common WHERE statement such as this:

... WHERE
(
    (DATE_FORMAT(DATE(akDate), '%a') = 'SAT')
    AND
    (WHERECLAUSE1)
)
OR
(
    (DATE_FORMAT(DATE(akDate), '%a') != 'SAT')
    AND
    (WHERECLAUSE2)
)

where, of course, you should replace WHERECLAUSE1 and WHERECLAUSE2 with appropriate conditions.

like image 114
Tadeck Avatar answered Dec 28 '22 22:12

Tadeck