MySQL how to make negative results possible when subtracting unsigned values?
mysql
Solution
Cast as SIGNED each number before LEAST and before substract
SELECT
(LEAST(CAST(`a`.`price` AS SIGNED), CAST(`b`.`price` AS SIGNED)) - CAST(`c`.`price` AS SIGNED)) AS `diff`
...
ORDER BY `diff` DESC
Problem
I have three tables joined by left join. Here's the code: ``` SELECT (LEAST(`a`.`price, `b`.`price`) - `c`.`price`) AS `diff` ... ORDER BY `diff` DESC ``` The problem: `c`.`price` is greater than the LEAST, thus the subtraction is negative and throws BIGINT UNSIGNED value is out of range. How can I make it NOT throw this ridiculous error? This is result data, I'm not modifying the actual data in the table, so why does it not allow me to do this normally? I've tried `CAST(LEAST(...) AS SIGNED)` and casting both columns inside LEAST as signed, neither worked.