问题描述
有人知道我如何使IN子句以区分大小写的方式运行吗?我已经看到COLLATE可以与LIKE一起用于字符串搜索,但是我不知道它是否或如何与IN一起使用.例如,我想做
Does anyone know how I can make an IN clause behave in a case sensitive manner? I have seen that COLLATE can be used with LIKE for string searching but I don't know if or how it can be used with IN. For example I want to do something like
SELECT * FROM pages_table WHERE topic IN ('Food','NightLife','Drinks')
我希望它返回主题为食物"的页面,而不返回主题为食物"的页面,这是此查询当前发生的情况.谢谢.
And I want it to return pages where the topic is 'Food' but not those where the topic is 'food' which is currently what happens on this query. Thanks.
推荐答案
您实际上可以像在其他示例中看到的那样使用它:
You can actually use it as you have likely seen in other examples:
SELECT *
FROM pages_table
WHERE CAST(topic AS CHAR CHARACTER SET latin1)
COLLATE latin1_general_cs IN ('Food','NightLife','Drinks')
这会将字符集更改为支持区分大小写的字符集,然后对列进行排序(根据您自己的字符编码,您可能不必这样做).
This changes the character set into one that supports case sensitivity and then collates the column (you may not have to do this depending on your own character encoding).
这篇关于使MySQL IN子句区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!