I would like to commit a query that would return a value if a calculation turns out TRUE and FALSE if FALSE.
SELECT
IF(VALID,EMPLOYEE_NAME,"NULL") AS NAME,
IF(SALARY/DAYS > 1000, TRUE, FALSE) AS VALID;
Seems like the VALID var is unknown to MYSQL until the query is over.
So my question is:
Is there any possible way to evaluate VALID for that query ?
You can also do this with a subquery:
I’m not a big fan of replicating logic. I much prefer to use subqueries to define variables. This makes it much easier to change the definitions. In general, this doesn’t affect performance, because (most) sql engines are smart enough to do the calculations with one read through the data.