I have a simple table with mixed values. For this example lets say i have 3 fields: key, value, and is_number. Key is any key, value is any value and is_number is 1 if value is a number and 0 if it is a string. Value has the type string.
Now i need to sort by values and i try to do the following:
SELECT *
FROM table
ORDER BY IF(is_number, CAST(value AS DECIMAL(20,10)), value)
But even though is_number is 1 for all rows it still sorts by the string value and not the casted integer value.
So i get a order like this 103, 111, 54 instead if the interger values that should give this 54, 103, 111
IF i remove the IF and just keep CAST(value AS DECIMAL(20,10) it works??
Anyone that can see what i do wrong?