Reputation: 302
I have a SQL table on PHPMyAdmin with two columns that both contains integers (see image)
When the row is empty, the value is 'null'. If I execute the following query:
SELECT * FROM `18-3-2019` WHERE `COL 13` < `COL 14`
I get the following result (left column is COL 13, right one is COL 14):
The problem is that the statement isn't always true, for example the output 12 being smaller than 6. I see the relation between numbers higher then 10 being in the output as they are lower than the other number. How do I fix this?
Upvotes: 0
Views: 440
Reputation: 43574
You need to CAST
the string values (VARCHAR
) to integers (INT
/ SIGNED
).
SELECT '12' < '6'; -- 1
using CAST(column AS SIGNED)
to compare the values:
SELECT 12 < 6; -- 0
SELECT CAST('12' AS SIGNED) < CAST('6' AS SIGNED); -- 0
Upvotes: 1