Locating potential duplicate before switching collation in MySQL

When you need to switch a fields collation you can check if any existing data will conflict with this change.

For example a keyword-field might contain data that is considered unique in one collation but not in another. The Swedish character ä is considered a unique character in swedish collation but in general collation it is only an a in an accented form.

Comparing the results from these two queries will show what effect, if any, an change in collation will have.

SELECT id, keyword AS KEY, count(*) AS num FROM keywords GROUP BY KEY HAVING num > 1;
SELECT id, keyword COLLATE utf8_unicode_ci AS KEY, count(*) AS num FROM keywords GROUP BY KEY HAVING num > 1;

Add Your Comments

Required
Required
Tips

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <ol> <ul> <li> <strong>

Your email is never published nor shared.

Ready?