0
0
SQLquery~5 mins

UPPER and LOWER functions in SQL

Choose your learning style9 modes available
Introduction
These functions change text to all uppercase or all lowercase letters. This helps to compare or display text in a consistent way.
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 uppercase or lowercase differences.
When cleaning up user input to store all text in lowercase for easier searching.
When formatting email addresses to lowercase before saving them.
When sorting text data ignoring case differences.
Syntax
SQL
UPPER(text_expression)
LOWER(text_expression)
Replace text_expression with the column name or text you want to change.
These functions return a new text value; they do not change the original data in the table.
Examples
Converts the string 'hello world' to all uppercase letters.
SQL
SELECT UPPER('hello world');
Converts the string 'HELLO WORLD' to all lowercase letters.
SQL
SELECT LOWER('HELLO WORLD');
Shows all employee names in uppercase.
SQL
SELECT UPPER(name) FROM employees;
Shows all user emails in lowercase.
SQL
SELECT LOWER(email) FROM users;
Sample Program
This creates a table with names, then shows each name in uppercase and lowercase.
SQL
CREATE TABLE people (id INT, name VARCHAR(20));
INSERT INTO people VALUES (1, 'Alice'), (2, 'Bob'), (3, 'Charlie');

SELECT id, UPPER(name) AS name_upper, LOWER(name) AS name_lower FROM people ORDER BY id;
OutputSuccess
Important Notes
UPPER and LOWER work only on text data types like VARCHAR or CHAR.
They do not change the original data stored in the database, only the output of the query.
Use these functions to make text comparisons case-insensitive by converting both sides to the same case.
Summary
UPPER converts text to all uppercase letters.
LOWER converts text to all lowercase letters.
Use them to format or compare text without case differences.