Sql模糊查询(like)区分大小写

  • A+
所属分类:PHP日常 函数

1、查询小写字母相关数据

SELECT * FROM address WHERE district LIKE '%m%'

2、查询大写字母相关数据

SELECT * FROM address WHERE district LIKE  '%M%'

问题:通过上面两条SQL语句,发现MySQL的like查询时不区分大小写的

解决方法(查询时指定区分大小写):在like后面加个binary就OK了,或者在查询字段前面加binary

SELECT * FROM address WHERE district LIKE BINARY  '%m%'
SELECT * FROM address WHERE district LIKE BINARY  '%M%'

 

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: