How to find all uppercase strings in a MySQL table?


To find all upper case strings in a MySQL table, you need to use BINARY UPPER() function. The syntax is as follows:

SELECT *FROM yourTableName WHERE yourColumnName=BINARY UPPER(yourColumnName);

To understand the above syntax, let us create a table. The query to create a table is as follows:

mysql> create table FindUpperCaseDemo
   -> (
   -> Id int,
   -> FirstName varchar(20),
   -> Age int
   -> );
Query OK, 0 rows affected (1.04 sec)

Insert some records in the table using insert command. The query is as follows:

mysql> insert into FindUpperCaseDemo values(1,'John',23);
Query OK, 1 row affected (0.17 sec)
mysql> insert into FindUpperCaseDemo values(2,'CAROL',21);
Query OK, 1 row affected (0.29 sec)
mysql> insert into FindUpperCaseDemo values(3,'JoHN',23);
Query OK, 1 row affected (0.11 sec)
mysql> insert into FindUpperCaseDemo values(4,'JOHN',26);
Query OK, 1 row affected (0.22 sec)
mysql> insert into FindUpperCaseDemo values(5,'sAM',26);
Query OK, 1 row affected (0.18 sec)
mysql> insert into FindUpperCaseDemo values(6,'SAM',28);
Query OK, 1 row affected (0.18 sec)
mysql> insert into FindUpperCaseDemo values(7,'MIKE',29);
Query OK, 1 row affected (0.17 sec)
mysql> insert into FindUpperCaseDemo values(8,'BOB',20);
Query OK, 1 row affected (0.45 sec)
mysql> insert into FindUpperCaseDemo values(9,'LARRY',22);
Query OK, 1 row affected (0.39 sec)
mysql> insert into FindUpperCaseDemo values(10,'LARRy',22);
Query OK, 1 row affected (0.14 sec)

Display all records from the table using select statement. The query is as follows:

mysql> select *from FindUpperCaseDemo;

The following is the output:

+------+-----------+------+
| Id   | FirstName | Age  |
+------+-----------+------+
|    1 | John      |   23 |
|    2 | CAROL     |   21 |
|    3 | JoHN      |   23 |
|    4 | JOHN      |   26 |
|    5 | sAM       |   26 |
|    6 | SAM       |   28 |
|    7 | MIKE      |   29 |
|    8 | BOB       |   20 |
|    9 | LARRY     |   22 |
|   10 | LARRy     |   22 |
+------+-----------+------+
10 rows in set (0.00 sec)

Here is the query to find all uppercase strings in a MySQL table:

mysql> select *from FindUpperCaseDemo where FirstName=BINARY UPPER(FirstName);

The following is the output:

+------+-----------+------+
| Id   | FirstName | Age  |
+------+-----------+------+
|    2 | CAROL     |   21 |
|    4 | JOHN      |   26 |
|    6 | SAM       |   28 |
|    7 | MIKE      |   29 |
|    8 | BOB       |   20 |
|    9 | LARRY     |   22 |
+------+-----------+------+
6 rows in set (0.09 sec)

Updated on: 30-Jul-2019

741 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements