Is it possible to have a SELECT statement in mySQL with an IF/ELSE clause in it?
E.g.
I want to SELECT all table rows and return color2 ONLY if color2 is 'brown'. My example SQL select statement of what I would like to accomplish is below.
APPLES +------+--------+----------+----------+ | ID | NAME | COLOR1 | COLOR2 | +------+--------+----------+----------+ | 1 | apple1 | red | brown | +------+--------+----------+----------+ | 2 | apple2 | red | green | +------+--------+----------+----------+
SELECT name, (IF color2 = 'brown' SELECT color2 ELSE SELECT color1) AS color FROM apples
would return:
+----------+----------+ | apple1 | brown | +----------+----------+ | apple2 | red | +----------+----------+