How do I perform an IF...THEN
in an SQL SELECT
statement?
For example:
SELECT IF(Obsolete = \'N\' OR InStock = \'Y\' ? 1 :
I like the use of the CASE statements but the question asked for an IF statement in the SQL Select. What I've used in the past has been:
SELECT
if(GENDER = "M","Male","Female") as Gender
FROM ...
It's like the excel or sheets IF statements where there is a conditional followed by the true condition and then the false condition:
if(condition, true, false)
Furthermore, you can nest the if statements (but then use should use a CASE :-)
(Note: this works in MySQLWorkbench but may not work in other platforms)