How to Use the LOWER() Function in MySQL

08/06/2021

Contents

In this article, you will learn how to use the LOWER() function in MySQL.

Using the LOWER() function in MySQL

In MySQL, the LOWER() function is used to convert all characters in a string to lowercase.

Syntax

LOWER(str);

Examples

Here are some examples of using the LOWER() function in MySQL:

Converting a string to lowercase

To convert a string to lowercase, you can use the LOWER() function.

Syntax
SELECT LOWER(str);
Example
SELECT LOWER('HELLO WORLD');

Output:

+-----------------+
| LOWER('HELLO WORLD')|
+-----------------+
| hello world     |
+-----------------+

In this example, the LOWER() function returns the string ‘hello world’, which is the lowercase version of the input string ‘HELLO WORLD’.

Converting column values to lowercase

You can also use the LOWER() function to convert column values to lowercase.

Syntax
SELECT LOWER(column_name) FROM table_name;
Example
SELECT LOWER(name) FROM employees;

Output:

+--------+
| LOWER(name)|
+--------+
| john   |
| ann    |
| rich   |
| sara   |
+--------+

In this example, the LOWER() function returns the lowercase version of the name column in the employees table.

Using lowercase values in a WHERE clause

You can use the LOWER() function in a WHERE clause to filter records based on lowercase values.

Syntax
SELECT * FROM table_name WHERE LOWER(column_name) = string_value;
Example
SELECT * FROM employees WHERE LOWER(name) = 'john';

Output:

+----+------+--------+------------+
| id | name | salary | hire_date  |
+----+------+--------+------------+
| 1  | John | 50000  | 2020-01-01 |
+----+------+--------+------------+

In this example, the SELECT statement returns all the records from the employees table where the name column is equal to ‘john’ in lowercase.