What if you could find any name no matter how it's typed, with just one simple trick?
Why UPPER and LOWER functions in SQL? - Purpose & Use Cases
Imagine you have a list of customer names written in different ways: some in all caps, some in all lowercase, and some mixed. You need to find all customers named "john" but the spelling varies in case.
Manually checking each name for every possible case variation is slow and tiring. It's easy to miss matches or make mistakes because you have to remember all the ways "john" could be written.
The UPPER and LOWER functions let you change all text to the same case automatically. This way, you can compare names without worrying about how they were typed.
WHERE name = 'john' OR name = 'John' OR name = 'JOHN'
WHERE LOWER(name) = 'john'You can easily find and compare text data regardless of how it was typed, making searches and filters much simpler and more reliable.
A store wants to send a special offer to all customers named "Anna". Using LOWER, they find everyone named "anna", "ANNA", or "Anna" without missing anyone.
Manual text matching is slow and error-prone.
UPPER and LOWER standardize text case for easy comparison.
This makes searching and filtering text data simple and accurate.
Practice
UPPER('Hello World') return?Solution
Step 1: Understand the UPPER function
The UPPER function converts all letters in the input string to uppercase letters.Step 2: Apply UPPER to 'Hello World'
Converting each letter to uppercase results in 'HELLO WORLD'.Final Answer:
'HELLO WORLD' -> Option BQuick Check:
UPPER('Hello World') = 'HELLO WORLD' [OK]
- Confusing UPPER with LOWER
- Thinking it changes only first letter
- Assuming it reverses the string
name to lowercase in SQL?Solution
Step 1: Recall correct function syntax
The LOWER function is called with parentheses around the column name: LOWER(column_name).Step 2: Check each option
SELECT LOWER(name) FROM table; uses correct syntax: LOWER(name). Others have syntax errors or invalid notation.Final Answer:
SELECT LOWER(name) FROM table; -> Option AQuick Check:
Use LOWER(column) with parentheses [OK]
- Omitting parentheses
- Using dot notation like name.LOWER()
- Using square brackets inside function
users with a column username containing values: 'Alice', 'BOB', 'charlie', what will the query SELECT LOWER(username) FROM users; return?Solution
Step 1: Understand LOWER function effect on each username
LOWER converts all letters to lowercase regardless of original case.Step 2: Apply LOWER to each username
'Alice' -> 'alice', 'BOB' -> 'bob', 'charlie' -> 'charlie'.Final Answer:
['alice', 'bob', 'charlie'] -> Option CQuick Check:
LOWER converts all letters to lowercase [OK]
- Assuming only first letter changes
- Confusing LOWER with UPPER
- Expecting mixed case output
SELECT LOWER username FROM users;Solution
Step 1: Check function syntax
SQL functions require parentheses around arguments, so LOWER(username) is correct.Step 2: Identify missing parentheses
The query uses LOWER username without parentheses, causing syntax error.Final Answer:
Missing parentheses around column name -> Option DQuick Check:
Functions need parentheses [OK]
- Omitting parentheses for functions
- Assuming functions work like keywords
- Ignoring syntax errors
products where the category column equals 'Books', ignoring case differences. Which SQL WHERE clause correctly does this?Solution
Step 1: Understand case-insensitive comparison
To ignore case, convert both sides to the same case before comparing.Step 2: Apply LOWER and UPPER to category and compare both
Using WHERE LOWER(category) = 'books' AND UPPER(category) = 'BOOKS' ensures the category matches 'Books' ignoring case by checking both lowercase and uppercase.Final Answer:
WHERE LOWER(category) = 'books' AND UPPER(category) = 'BOOKS' -> Option AQuick Check:
Use both LOWER and UPPER on the column to ensure case-insensitive match [OK]
- Comparing without case conversion
- Mixing cases in comparison string
- Using only one case function
Ready to prove it?
Pass the test and this pattern moves unknown
