Skip to content
Advertisement

Check for Lowercased First Character in String Value for MariaDB

In my MariaDB environment I want to check to see if there are any values in the table “contacts” and the column “firstname”, where the first letter in the string value is lower case. My question is: will this do the trick?

  SELECT * FROM contacts
  WHERE (firstname) LIKE '%[abcdefghijklmnopqrstuvwxyz]%';

Advertisement

Answer

MySQL does not support syntax [...] with LIKE.

You can also use the following condition to check if the first character of firstname is lowercased:

BINARY lower(left(firstname, 1)) = left(firstname, 1)  

Another option is to use a regex (shorter to write and easier to understand):

BINARY firstname RLIKE '^[a-z]'

Please note that both expressions will not use an existing index on firstname, since functions or regexes comes into play.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement