Finding integer value in varchar field in MySQL

I have a table named user

as shown below:

id || email
---------------------------------
1  || someone@foo.bar
---------------------------------
2  || 1manwithblueshirt@bar.foo
---------------------------------

      

Why is this:

1manwithblueshirt@bar.foo

      

The result of this search?

SELECT * FROM user WHERE email = 1

      

+3


source to share


1 answer


As MySQL decides to convert the email to integer. The rules are to convert leading characters to a number as long as the characters are not valid numbers.

Here's a simple example:



select (case when '1abc' = 1 then 'a' else 'b' end)

      

+5


source







All Articles