MySQL LOWER() Function

Summary: in this tutorial, you will learn how to use the MySQL LOWER() function to return the lowercase of a string.

Introduction to MySQL LOWER() function

In MySQL, the LOWER() function accepts a string argument and returns the lowercase version of that string.

Here is the syntax of the LOWER() function:

LOWER(str)Code language: SQL (Structured Query Language) (sql)

In this syntax, the str is the argument that you want to convert to the lowercase.

Alternatively, you can use the LCASE() function which returns the same result:

LCASE(str)Code language: SQL (Structured Query Language) (sql)

Note that to convert a string to uppercase, you use the UPPER() function.

MySQL LOWER() function examples

Let’s take some examples of using the LOWER() function.

1) Using LOWER() function to convert a literal string to lowercase

This example uses the LOWER() function to convert the string MySQL to lowercase:

SELECT 
    LOWER('MySQL');Code language: SQL (Structured Query Language) (sql)

Here is the output:

+----------------+
| LOWER('MySQL') |
+----------------+
| mysql          |
+----------------+
1 row in set (0.00 sec)Code language: JavaScript (javascript)

2) Using LOWER() function with data in the table

See the following employees table from the sample database:

MySQL LOWER() - Sample Table

This example uses the LOWER() function to convert the first name of employees to lowercase.

SELECT 
    firstname, 
    LOWER(firstname) lowercase
FROM
    employees
ORDER BY 
    firstname
LIMIT 10;Code language: SQL (Structured Query Language) (sql)

The following picture shows the output:

MySQL LOWER Function example

Handling binary string data

The LOWER() function is not effective when applied to the binary string data such as BINARY, VARBINARY, and BLOB

Therefore, before passing this data to the LOWER() function, you need to convert the string to a nonbinary string.

See the following example:

SET @str = BINARY 'BINARY STRING';
SELECT LOWER(@str), LOWER(CONVERT(@str USING utf8mb4));Code language: SQL (Structured Query Language) (sql)

Here is the output:

+---------------+---------------+
| LOWER(@str)   | lower_case    |
+---------------+---------------+
| BINARY STRING | binary string |
+---------------+---------------+
1 row in set (0.00 sec)Code language: JavaScript (javascript)

As you can see clearly from the output, the LOWER() function has no effect on the binary string.

Summary

  • Use the MySQL LOWER() function to convert a string to lowercase.
Was this tutorial helpful?