3

MySQL query returns a record, even when the condition not satisfied.

SELECT * FROM `orders` WHERE order_id = '10000R'

There is no record that will match the WHERE condition given here. But MySQl return a record with order_id = 10000

Looks like WHERE condition ignoring the alpha within quotes. Please help me if there is anything wrong in the query or is this a MySql bug

4 Answers 4

3

I'm assuming that order_id is an int, and that MySql is implicitly casting the varchar '10000R' to match the data type of the column, which strips the trailing 'r'.

See "Type Conversion in Expression Evaluation" in the MySql docs.

2

The order_id is probably an integer field of some type. MySQL will cast the string '1000R' to an integer 1000. That's why you're getting the result back. It's not a bug.

0

Make sure your order_id field is not an integer or other numeric field. If it is, it might be ignoring the trailing alpha.

MySQL integer comparison ignores trailing alpha characters

1
  • ... and those are the three of the fastest same answers you'll ever get. :)
    – trpt4him
    Nov 16, 2012 at 21:38
-1

MySql table data type is VARCHAR. please change your data type.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.