I have a database table with an id
column (VARCHAR(32)
).
I don't understand why this query behaves this way:
SELECT * FROM my_table where `id`=40000;
I have 1 Row returned with the id 4e4a2269774a0032fbca2b4692b560b3
I did some tests and I have the following behaviour
SELECT *, case when (cast(`id` as unsigned)=40000) then '40000' else 'not 40000' end FROM my_table where `id`=40000;
Same row returned with 'not 40000'.
SELECT * FROM my_table where `id`=CAST(40000 as char);
No rows returned.
MySQL version is 8.0.15-commercial.
Why is this row returned, when the id is clearly not the one I asked ? How are the cast and comparison done ?
To reproduce this weird behaviour, here is a fiddle thanks to @MadhurBhaiya https://www.db-fiddle.com/f/mwQ9hUVgDisBBBajCFKVHQ/1