I’m trying to search records using an alphanumeric “short_code” column. Something like:
SELECT * FROM items WHERE short_code = "1AV9"
With no collation and with column type set to varchar(), this query is case-insensitive, so it returns records with short_codes 1av9, 1Av9, etc. I don’t want this.
So I tried changing the collation of the short_code column to utf8_bin, but now the query isn’t returning anything at all. However, if I change the query to:
SELECT * FROM items WHERE short_code LIKE "1AV9%"
Then I get the exact row I want. Is it possible that by converting my column’s collation, it somehow appended invisible chars at the end of all my shortcodes? How can I verify/fix this?
EDIT: It looks that by changing my column type to binary and trying a bunch of other stuff, it somehow padded all my short_codes with null bytes, which explains why the query wouldn’t return any result. After starting over and setting the utf8_bin collation, everything’s working as expected.
Try
and see if you get something other than 4 as the result.
Edit: Hmm, your values might have trailing spaces. Try
(that’s
1AV9plus four spaces) and see if you get any results.