Does MySQL make it possible to do something like:
SELECT username, age, age>13 AS ageGT FROM users.
And get something like:
+--------+---+-----+
|username|age|ageGT|
+--------+---+-----+
|fred |14 |true |
|bob |12 |false|
+--------+---+-----+
?
This would be a huge help, thanks!
Clarification: I’m not looking for a WHERE clause, I want to select both cases, but have a column showing whether the clause evaluates true or false.
You can do
CASE WHEN age > 13 THEN 'true' ELSE 'false' END AS ageGT:Or more simply:
Read more on CASE Expressions and the IF() Function.
An important difference is that the
CASEexpression syntax is supported by all major DBMSs, whereasIF()is pretty much MySQL specific.