3

I have a query like this :

SELECT * FROM category_keyword  WHERE keyword = 'cho'

This query is return result keyword ={ cho , chợ , chờ , chợ ...}. I only want the result is keyword = 'cho' ( not 'chợ, chờ ...') . How can I do? The collation of table is utf8_unicode_ci

2
  • SELECT * FROM category_keyword WHERE CONVERT(keyword USING utf8) = 'cho' Perhaps?
    – ʰᵈˑ
    Mar 23, 2015 at 16:49
  • The result still include keyword = 'chợ '...
    – abent
    Mar 23, 2015 at 16:55

2 Answers 2

5

With utf8 collation, cho does equal chờ. If you want to compare as binary:

SELECT * FROM category_keyword WHERE keyword = CONVERT('cho' USING binary)
1
  • 1
    I searched forever for this kind of answer. Who gets the idea to use USING binary when the field is UTF8 and the search word/characters are UTF8...
    – Avatar
    Feb 18 at 14:29
1

Change the collation for the column to utf8_bin. This is better than using CONVERT because it allows the use of an index. However, if you sometimes need utf8_bin (exact match) and sometimes need utf8_unicode_ci (for case folding and accent stripping), you are out of luck, performance-wise.

1
  • Yikes. @Marcus Adams solution may be using the index. But I don't know how!
    – Rick James
    Mar 24, 2015 at 0:14

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.