Convert Uppercase Characters to Lowercase to Compare Data in MySQL

A database is a collection of information that is organized in a meaningful way. A MySQL Database stores data and retrieves it easily when needed.

What does this mean for you? It means your business can grow faster without the need to worry about how fast your system will be able to handle the increase in volume! MySQL offers many functions to help query data faster and easier.

Lower() and Lcase() are 2 methods which we will introduce in this post.

MySQL offers a LOWER() function which can convert a field’s characters to lowercase. Besides, we can use the LCASE() function, which is a synonym for LOWER().

Syntax:

LOWER(str)
LCASE(str)

Usage:

//convert a field's value to lowercase
SELECT LOWER(post_title) FROM `wp_posts`
SELECT LCASE(post_title) FROM `wp_posts`
//convert any string
SELECT LOWER('Uppercase')
SELECT LCASE('Uppercase')

//more examples
SELECT LOWER('HELLO WORLD'); -- Output: 'hello world'
SELECT LOWER('HELLO WORLD'); -- Output: 'hello world'
SELECT * FROM users WHERE LOWER(name) LIKE LOWER('%john%');
UPDATE users SET status='active' WHERE LOWER(email) = LOWER('[email protected]');
SELECT * FROM users ORDER BY LOWER(name);
SELECT * FROM table1 JOIN table2 ON LOWER(table1.col) = LOWER(table2.col);
SELECT DISTINCT LOWER(email) FROM users;
INSERT INTO users (username) VALUES (LOWER('USERNAME'));
SELECT LOWER(department), COUNT(*) FROM employees GROUP BY LOWER(department);
SET @username = 'USER';
SELECT * FROM users WHERE LOWER(username) = LOWER(@username);

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close