且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL查询-使用ORDER BY rand()强制区分大小写

更新时间:2023-02-15 17:32:33

字符的顺序和相等性由

The order and equality of characters is defined by the collation. In most cases, a case-insensitive collation is used.

如果需要对特定的基准使用严格的,区分大小写的比较,请使用

If you need to use a strict, case-sensitive comparison for a specific datum, use the BINARY operator:

mysql> SELECT 'a' = 'A';
        -> 1
mysql> SELECT BINARY 'a' = 'A';
        -> 0
mysql> SELECT 'a' = 'a ';
        -> 1
mysql> SELECT BINARY 'a' = 'a ';
        -> 0

所以在您的情况下:

SELECT g_path FROM glyphs WHERE BINARY g_glyph = :g_glyph ORDER BY rand()