abent
abent

Reputation: 319

matching exactly word in utf8 in where clause mysql

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

Upvotes: 3

Views: 2526

Answers (2)

Rick James
Rick James

Reputation: 142540

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.

Upvotes: 1

Marcus Adams
Marcus Adams

Reputation: 53880

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

SELECT * FROM category_keyword WHERE keyword = CONVERT('cho' USING binary)

Upvotes: 6

Related Questions