← Back to MySQL Course | Chapter 12: String Functions | Lesson 3 of 7

UPPER & LOWER

Convert to Uppercase

The UPPER function converts all letters in a text string to capital letters. Any non-letter character remains unchanged, so numbers and punctuation pass through the function untouched.

Example: Convert to Uppercase

sql
SELECT UPPER('hello world 123!') AS shouted;

Convert to Lowercase

The LOWER function converts all uppercase letters in a text string into small letters. This is ideal for standardizing inputs, such as normalizing email addresses before checking them for duplicates.

Example: Convert to Lowercase

sql
CREATE TABLE users (id INT, email TEXT);
INSERT INTO users VALUES (1, '[email protected]');
SELECT LOWER(email) AS normalized_email FROM users;

Case Insensitive Comparisons

You can use LOWER or UPPER to do case-insensitive comparisons manually, especially when working with binary collation tables where MySQL would otherwise treat Apple and apple as different strings.

Example: Case Insensitive Comparisons

sql
CREATE TABLE fruits (id INT, name TEXT);
INSERT INTO fruits VALUES (1, 'Apple'), (2, 'apple');
SELECT * FROM fruits WHERE LOWER(name) = LOWER('APPLE');

Combining with CONCAT

UPPER and LOWER can be combined with CONCAT to create customized print messages and system alert values, such as building an uppercase warning label out of otherwise mixed-case data.

Example: Combining with CONCAT

sql
CREATE TABLE alerts (id INT, level TEXT, message TEXT);
INSERT INTO alerts VALUES (1, 'warning', 'disk space low');
SELECT CONCAT(UPPER(level), ': ', message) AS alert_line FROM alerts;

Formatting Output Names

You can clean up poorly formatted user records by applying UPPER and LOWER functions directly to your select lists, such as displaying names in Title Case-adjacent consistent casing without altering the stored data itself.

Example: Formatting Output Names

sql
CREATE TABLE users (id INT, first_name TEXT);
INSERT INTO users VALUES (1, 'AMIT');
SELECT CONCAT(UPPER(LEFT(first_name, 1)), LOWER(SUBSTRING(first_name, 2))) AS clean_first_name FROM users;
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.