I have a table with a column name
. The values in this column can be capitalized or not (e.g. both "adam" and "Adam"). How can I select only values that are capitalized (start with an uppercase letter)?
Asked
Active
Viewed 512 times
3 Answers
2
If you're using SQLite3, you can employ the REGEXP
expression
WHERE name REGEXP '^[A-Z]'
There's some good information in this answer regarding installation ~ https://stackoverflow.com/a/8338515/283366

Phil
- 157,677
- 23
- 242
- 245
0
You can be explicit with collate binary
and a comparison:
where name collate binary = 'Adam' collate binary
However, binary
is often the default so it is probably not necessary.
If you mean any capitalized letter, then:
where substr(name, 1, 1) collate binary = 'A' collate binary

Gordon Linoff
- 1,242,037
- 58
- 646
- 786
-
1Whilst required, I don't think this answers the question of *"How can I select only values that are capitalized (start with an uppercase letter)?"* – Phil Jul 27 '17 at 00:16
-
@Phil . . . I see what you mean. Your interpretation makes more sense. – Gordon Linoff Jul 27 '17 at 00:17
-
1I want to search all names, and the names in the column don't just start with A, it can be any letter. – Chin Jul 27 '17 at 00:19
0
An elegant way of doing it using REGEX:
SELECT *
FROM 'your_table'
WHERE 'field' REGEXP BINARY '^[A-Z]'

Sletheren
- 2,435
- 11
- 25
-
-
Of course you'll use the other quotes (I didn't use them here cause they're interpreted as a code sample :) – Sletheren Jul 27 '17 at 00:24
-
1You can use graves / backticks in code samples. SQLite also supports square-bracket identifiers – Phil Jul 27 '17 at 00:25