I need help translating this into a MySQL statement. I need to do something like:
WHERE IF 'field1 > 0' THEN 'field2 < field1'
Right now, I have this MySQL statement, but doesn’t work?:
SELECT * FROM `my_table` WHERE IF(field1>0, field2<field1, 1=1) AND field3='1';
Please advise a solution for this. Thank you!
You can achieve this by using logical ANDs and ORs.
The
<else part of the statement>is the condition that you want to check iffield1is not> 0, unless there is no such a clause, in which case remove the OR and everything after it.