Question

When working with MySQL, how can I fetch all rows where the name column is all uppercase?

Since equality is case insensitive, I'm not quite sure how to do this.

Was it helpful?

Solution

If your column collation is case insensitive, you can override it in your query:

SELECT * FROM my_table WHERE my_column COLLATE latin1_bin = UPPER(my_column);

COLLATE clause syntax.

OTHER TIPS

SELECT * FROM my_table REGEXP '^[[:upper:]]+$';

SELECT * FROM table where binary your_field REGEXP '^[[:upper:]]+$'

Similarly:

SELECT * FROM table where binary your_field REGEXP '^[[:upper:]]+$'

The 'binary' casts the field to binary which is necessary for REGEXP to be case-sensitive with most data types (except binary, of course).

[:character_class:] notation is documented here - there are several other useful character classes.

'binary' operator is documented here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top