mysql完全匹配的地方 [英] mysql where exact match
本文介绍了mysql完全匹配的地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我编写此查询时
SELECT cd.title, cd.city FROM coupon_detail cd WHERE cd.id = 260;
返回
title city
--------------- ------
Butterfly world Mohali
当我写
SELECT cd.title, cd.city FROM coupon_detail cd WHERE cd.id = '260abcxyz';
返回
title city
--------------- ------
Butterfly world Mohali
看到第二个错误.我想仅在ID ID完全匹配时获取值...如何解决此问题.谢谢您的帮助.
see the second one is wrong. i want to get the value only IF ID EXACTLY MATCH ... how to solve this. thanks for your help.
推荐答案
您可以将id
转换为字符串,以便准确进行比较.您可以使用LIKE
进行隐式转换
You could convert the id
to a string so the comparison will be done exactly. You could use LIKE
to cause an implicit conversion
SELECT cd.title, cd.city FROM coupon_detail cd WHERE cd.id LIKE '260abcxyz';
或其他方式,您可以显式执行投射
or alternative, you can perform the cast explicitly
SELECT cd.title, cd.city FROM coupon_detail cd WHERE CAST(cd.id AS CHAR) = '260abcxyz';
但是,如果您所有的ID都是整数,则在尝试查询数据库之前检查这些值可能更合适. (如果您要查询的ID不是数字,则始终无法匹配.)
However, if all your IDs are integers, it's probably more appropriate to check these values before you try to query the database. (If the ID you're querying with isn't a number, there can't be a match anyway.)
这篇关于mysql完全匹配的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文