2013-05-22 22 views
3

我有一個小麻煩:MySQL的比較兩個字符串與民族特色

SELECT * FROM tableName tn WHERE LOWER(tn.name) = LOWER('place_string_here'); 

這沒關係,當它完美契合:

tn.name = orange_tree

place_string_here = Orange_Tree

但我的問題是:民族特色,如:

Hästgård

我希望 「Hästgård」,以適應: Hästgård, Hästgard, Hastgård和/或 Hastgard

有沒有什麼聰明的方法來做到這一點?

+1

哪個字符集是你使用(和整理) –

+1

你見過這篇文章:http://stackoverflow.com/questions/5529013 /問題排序瑞典字符MySQL的 – vikingsteve

回答

0

我對該字段的latin1_swedish_ci COLLATION導致了該錯誤。 將排序規則更改爲utf8_general_ci(「名稱」字段)後,它開始正常工作:-)

2

您可以使用:

您的疑問:

SELECT * 
FROM tableName tn 
WHERE tn.name COLLATE 'utf8_general_ci' = 'place_string_here' 

SQLFIDDLExample

VALUES 
('Hästgård', '[email protected]'), 
('Twitter', '@sqlfiddle'); 

查詢:

select id, type 
from t 
where type COLLATE 'utf8_general_ci' = 'hastgard' 

結果:

| ID |  TYPE | 
----------------- 
| 1 | Hästgård |