假设我有如下语句
select * from table where column in (select other_column from other_table)
但我希望仅当列“binary”等于 other_column 时才匹配。有点像“类似二进制”,但对于“in”运算符。
我希望问题很清楚。 谢谢 :)
最佳答案
你可以这样做:
select * from table where BINARY column in (select other_column from other_table)
或
select * from table where column in (select BINARY other_column from other_table)
但是这两者的性能会很糟糕,因为你要求 mysql 在它可以比较之前对所有值进行类型转换。
最好按照另一条评论的建议将查询重写为 JOIN,但是这样一来,您仍然会遇到连接要对其进行类型转换的值的问题,并且不能使用索引。
比这更好的是,如果你想在这个字段上区分大小写或精确比较,然后将表中的字符集更改为列的 BINARY,或者使用 _cs 的排序规则
像往常一样,手册会告诉您所有这些 MySQL Character sets and Collations
关于mysql - 如何在Mysql二进制中制作 "In"运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11379536/