Recently noticed that a working UPDATE query has no longer same results with where clause that contains alphanumeric values leading with number, appreciate any help.
UPDATE query:
UPDATE `user` SET last_name = 'newTest' where `identifier` = '123abc';
ISSUE: This query updates all records with identifier begins with 123...
Fixed temporary the issue by using LIKE (see below):
UPDATE `user` SET last_name = 'newTest' where `identifier` LIKE '123abc';
But afraid there is some other similar cases in my code that could causes unacceptable data loss for clients.
EDIT: query with the issue is when I update another identifier that has the exact number leading other identifiers:
UPDATE `user` SET last_name = 'newTest' where `identifier` = 123;
Tech. versions used: php 7, mysql 5.6, RedBean 5, OS Alpine 3.11
The problem is that you compare a string value and a numeric value:
so Mysql does an implicit conversion of the column
identifierto numeric and since the values123abcor123...start with123, they are all converted to123and the condition returnsTRUEfor all the values that start with123.You can see this behavior here.
What you want is string comparison.
So change to:
This way you do a string comparison.