I have column a and column b in table emp. I'd like to retrieve values from those columns and find the difference between them with a function. The function would return true for a 0 difference otherwise return false. I don't know how to return a value.
Also, how do I store the retrieved values in a variable?
MySQL doesn't really have booleans. TRUE and FALSE are aliases to 1 and 0, and the BOOL column type is just an alias for TINYINT(1). All expressions that appear to give boolean results actually return 0 or 1.
You could write your query as:
SELECT (a = b) AS a_equals_b
FROM emp
WHERE ...
select a, b, if(a-b=0, true, false) as diff from emp;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With