2013-04-24 152 views
1

我有一個區分大小寫的colume(utf8_bin整理)。 我需要不區分大小寫地搜索字符串,並且以不區分大小寫的方式對結果進行排序。在區分大小寫的列中忽略大小寫的搜索(並且不區分大小寫)

是否寫過此查詢。

SELECT customer_name 
    FROM customers 
    WHERE CONVERT(customer_name USING UTF8) LIKE 'aB%' 
    ORDER BY CONVERT(customer_name USING UTF8) 
    LIMIT 0,10 

這是否高效?還是有更好的方法來實現這一目標?

回答

2

如何轉換大寫?

SELECT customer_name 
    FROM customers 
    WHERE UPPER(customer_name) LIKE 'AB%' 
    ORDER BY UPPER(customer_name) 
    LIMIT 0,10 
+1

是的。我最初是這麼做的。但是我看到[這裏](http://stackoverflow.com/a/2876802/1137788)這會影響索引的使用。因此我使用了Collat​​e。 – SatheeshJM 2013-04-24 11:42:58

+0

感謝您分享鏈接。我不知道Collat​​e;) – TheEwook 2013-04-24 11:47:44