mysql query select like with diacritic Turkish letters

微笑、不失礼 提交于 2019-12-24 01:38:09

问题


I have a token table in Turkish; it's default collation is utf8_general_ci On FreeBSD server, mysql version is 5.6.15

I want to query;

select * from tokens where type like 'âmâ';

or

select * from tokens where type='âmâ';

With these queries, result must be one unique for 'âmâ' (it means 'blind' in Turkish also) But i have four raw result;

result 1 "amâ" means 'but'
result 2 "ama" means 'but'
result 3 "âma" means 'blind'
result 4 "âmâ" means 'blind'

that didnt i want.

I tried different collations and character sets and names. But same results with working ones.

Any help please


回答1:


You could force a binary comparison:

SELECT * FROM tokens WHERE BINARY type='âmâ';

please see the documentation of the binary operator.




回答2:


The Turkish collation is latin5_turkish_ci. See: Character Sets and Collations in MySQL.

Use the COLLATE keyword in the WHERE-clause.

SELECT *
FROM tokens
WHERE type = 'âmâ' COLLATE latin5_turkish_ci;

I have not tested it. I hope it helps.

See: Using COLLATE in SQL Statements and Collation of Expressions.



来源:https://stackoverflow.com/questions/22454999/mysql-query-select-like-with-diacritic-turkish-letters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!