SELECT * FROM families WHERE id = '65ae3ee2-aeb2-427f-8381-56db91b94363' OR fam_code = '65ae3ee2-aeb2-427f-8381-56db91b94363' query SELECT * FROM families WHERE id = '65ae3ee2-aeb2-427f-8381-56db91b94363' OR fam_code = '65ae3ee2-aeb2-427f-8381-56db91b94363' returns two entries:

 id fam_code 65 c648b66e-ae0c-467b-af56-1e6d3c214f2e 92 65ae3ee2-aeb2-427f-8381-56db91b94363 

Why is that?

  • And id is accidentally not a numeric type? - pavel
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

You compare a numeric field with a string. In this case, MySQL converts the string to a number. And when converting a string to a number, MySQL tries to compile this number from all decimal digits from the beginning of the string to the first non-digit. Thus, when casting to a number, line 65a... turns into the number 65.

It is checked by explicit type conversion:

 select cast('65abc' as unsigned), cast('abc65' as unsigned) Результат: 65, 0 
  • Understood thanks! - Dmitry Seleznev
  • one
    @ Dmitriy Seleznev, mark the answer as accepted - 4per