How to find all upper case strings in a MySQL table?

ThinkCode picture ThinkCode · Aug 23, 2012 · Viewed 13.6k times · Source

I initially thought this is trivial. Then thought 'binary' might do it. I am unsure at this point.

Name
----
John
MARY
Kin
TED

I would like to query just MARY and TED which are in all upper case. How would I query this?

Answer

Mark Byers picture Mark Byers · Aug 23, 2012

If your collation is case insensitive then you need to use a BINARY comparison:

SELECT *
FROM yourtable
WHERE Name = BINARY UPPER(Name)

See it working online: sqlfiddle