Query-Related Issues
Case Sensitivity in Searches
By default, MySQL searches are case-insensitive (although there are some character sets that are never case-insensitive, such as czech). That means that if you search with col_name LIKE 'a%', you will get all column values that start with A or a. If you want to make this search case-sensitive, use something like INSTR(col_name, "A")=1 to check a prefix. Or use STRCMP(col_name, "A") = 0 if the column value must be exactly "A".
Simple comparison operations (>=, >, = , < , <=, sorting, and grouping) are based on each character’s “sort value”. Characters with the same sort value (like E, e, and é) are treated as the same character!
In older MySQL versions LIKE comparisons where done on the uppercase value of each character (E == e but E <> é). In newer MySQL versions LIKE works just like the other comparison operators.
If you want a column always to be treated in case-sensitive fashion, declare it as BINARY. See Section 6.5.3.
If you are using Chinese data in the so-called big5 encoding, you want to make all character columns BINARY. This works because the sorting order of big5 encoding characters is based on the order of ASCII codes.
Problems Using DATE Columns
The format of a DATE value is 'YYYY-MM-DD'. According to ANSI SQL, no other format is allowed. You should use this format in UPDATE expressions and in the WHERE clause of SELECT statements. For example:
mysql> SELECT * FROM tbl_name WHERE date >= '1997-05-05';
As a convenience, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access