1

here is structure of myTable

----------------
|id|info1|info2|
----------------
|0 |abcde|fghij|
|1 |qwert|yuopa|
----------------

here is the query I call :

SELECT * FROM `myTable` WHERE `id` = 'a'

and it returns the first row which is

|0 |abcde|fghij|

what is happening? normally id is an integer but, by mistake I typed it as a string but I still got a result.

1
  • Can you show us the structure of myTable? I'm finding this difficult to replicate... Commented Apr 26, 2012 at 15:49

1 Answer 1

1

MySQL tries to cast 'a' as integer. The string does not contain any numeric values, so the result of the cast is 0. That's just how MySQL does casting.

SELECT 0 = 'a';

The above query returns 1 (TRUE).

SELECT CAST('a' AS SIGNED INTEGER);

The above query returns 0.

Sign up to request clarification or add additional context in comments.

1 Comment

@bluebrain well, there's that. But more importantly, you shouldn't compare ids in the table to strings. This is obviously a logical error in the query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.