3

I have this simple query

SELECT * 
FROM  `book` 
WHERE  `BookID` =  '7u'
LIMIT 1

i expect empty result But i see one result with book id =7. BookID is auto increment. Why query ignore 'u' character?

3
  • There are no "characters" in numbers, and BookID is a numeric field. Commented Dec 31, 2012 at 18:50
  • 1
    When you say this is the wrong result, what were you expecting? Did you want an empty result? (Presumably '7u' is not permitted in your BookID field). Commented Jan 1, 2013 at 13:25
  • you are right halfer. i edited my question. Commented Jan 1, 2013 at 14:31

3 Answers 3

4

Because 7u is not numeric, so apparently mysql is ignoring the u.

Maybe you are thinking of some high level programming languages which use suffixes to qualify the type of number? In C-derived languages, 7u would be an unsigned integer with value 7.

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

3 Comments

In other words, when you compare a numeric field against a non-numeric value, it probably converts it to an integer/number
can i do something to prevent this or any solution?
@user1903750: Remove the u. Why is it there in the first place? Also, look at the data. With an autoincrement column, it is strictly numeric.
0

Just because of two reasons:

  1. There may be only one record.

  2. you were using LIMIT 1. That display only one record from the output. so use LIMIT 5 OR 2.

1 Comment

hi. u missed my point. my question is i expect no result but i get one. check wallyk answer.
0

the mysql takes the string as 7u so when you try to do this stuff it coverts in a string but mysql is not in strict mode so it coverts string into integer because your id is intenger and its rounding of 7u becomes 7 thats why its display the one record try without quote 7u instead of '7u' then it gives error

Comments

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.