mysql where exact match

后端 未结 4 875
梦谈多话
梦谈多话 2021-01-14 04:47

When i write this query

SELECT cd.title, cd.city FROM coupon_detail cd WHERE cd.id = 260;

return

title            city  
--         


        
4条回答
  •  猫巷女王i
    2021-01-14 04:52

    This is happening because of Type Conversion in MySql. My sql treats '260abcxyz' as an integer in your query and AFAIK because first char is number MySql casts it to a number and it becomes only 260 and that's why you are getting result. If you write character first like 'abcxyz260' it will successes the comparison.

    More explanation available here: Type Conversion in MySql

    As a solution: you should take care that only numbers are passed in comparison and not combination of string and number.

提交回复
热议问题