raminious
raminious

Reputation: 161

Searching for an integer value in a varchar field in MySQL

I have a table named user like below:

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

Why is this:

1manwithblueshirt@bar.foo

result of this search?

SELECT * FROM user WHERE email = 1

Upvotes: 3

Views: 922

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271003

Because MySQL decides to convert the email to an integer. The rules are to convert leading characters to a number, until the characters are not valid numbers.

Here is a simple example:

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

Upvotes: 5

Related Questions