Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting all strings from database that starts with a lowercase letter

Tags:

sql

php

mysql

I'm trying to select all strings in my database that starts with a lowercase letter with regexp, but for some reason it's selecting all the strings that starts with a uppercase letter too. What am I doing wrong?

SELECT * 
FROM  `allData` 
WHERE response REGEXP  '^[a-z]'
LIMIT 0 , 30
like image 228
frosty Avatar asked Jun 16 '16 20:06

frosty


People also ask

How do I get just the lowercase letters in SQL?

Use the SQL LOWER() function if you want to convert a string column to lowercase. This function takes only one argument: the column whose values you want to lowercase. This function is a good choice if your database is case sensitive and you want to select only records matching a particular string.


1 Answers

From the MySQL REGEXP manual:

REGEXP is not case sensitive, except when used with binary strings.

You may therefore have some luck when using a binary string instead:

WHERE response REGEXP BINARY '^[a-z]'

Reasonably silly fiddle for demonstration: http://sqlfiddle.com/#!9/7eade/3

EDIT: As Ray says in the comments, you should probably use [[:lower:]] instead in order to work across all collations, e.g.

WHERE response REGEXP BINARY '^[[:lower:]]'
like image 120
slugonamission Avatar answered Sep 20 '22 17:09

slugonamission