0
0
MySQLquery~5 mins

UPPER and LOWER in MySQL

Choose your learning style9 modes available
Introduction
UPPER and LOWER help change text to all uppercase or all lowercase letters. This makes text easier to compare or display consistently.
When you want to make sure names are shown in all capital letters on a report.
When you need to compare two words without worrying about letter case differences.
When cleaning up user input to store all text in lowercase for consistency.
When searching for words in a database ignoring uppercase or lowercase differences.
Syntax
MySQL
UPPER(text)
LOWER(text)
Replace 'text' with the column name or string you want to change.
These functions return a new string with all letters changed to upper or lower case.
Examples
Changes the string 'hello world' to all uppercase letters.
MySQL
SELECT UPPER('hello world');
Changes the string 'HELLO WORLD' to all lowercase letters.
MySQL
SELECT LOWER('HELLO WORLD');
Shows all employee names in uppercase letters.
MySQL
SELECT UPPER(name) FROM employees;
Shows all customer city names in lowercase letters.
MySQL
SELECT LOWER(city) FROM customers;
Sample Program
This creates a table with usernames in mixed cases. Then it shows each username in uppercase and lowercase.
MySQL
CREATE TABLE users (id INT, username VARCHAR(20));
INSERT INTO users VALUES (1, 'Alice'), (2, 'Bob'), (3, 'CHARLIE');
SELECT id, UPPER(username) AS upper_name, LOWER(username) AS lower_name FROM users;
OutputSuccess
Important Notes
UPPER and LOWER only affect letters; numbers and symbols stay the same.
These functions are useful for case-insensitive searches when combined with WHERE clauses.
Remember that the output is a new string; the original data in the table does not change unless you update it.
Summary
UPPER(text) converts all letters in text to uppercase.
LOWER(text) converts all letters in text to lowercase.
Use these functions to standardize text for display or comparison.