📖 Scenario: You work at a bookstore database. The store wants to standardize how author names are displayed in reports. Some names are in uppercase, some in lowercase, and some mixed. You will use SQL functions to convert all author names to uppercase or lowercase.
🎯 Goal: Create a table of authors, then write queries using UPPER() and LOWER() functions to display author names in uppercase and lowercase.
📋 What You'll Learn
Create a table called authors with columns id (integer) and name (varchar).
Insert three authors with exact names: 'Jane Austen', 'mark twain', 'GEORGE ORWELL'.
Write a query to select all author names converted to uppercase using UPPER().
Write a query to select all author names converted to lowercase using LOWER().
💡 Why This Matters
🌍 Real World
Standardizing text case in databases helps keep reports and user interfaces consistent and professional.
💼 Career
Database developers and analysts often need to clean and format text data using functions like UPPER and LOWER.
Progress0 / 4 steps
1
Create the authors table and insert data
Create a table called authors with columns id as integer and name as varchar(50). Then insert these three rows exactly: (1, 'Jane Austen'), (2, 'mark twain'), and (3, 'GEORGE ORWELL').
MySQL
Hint
Use CREATE TABLE to make the table, then INSERT INTO to add rows.
2
Write a query to select author names in uppercase
Write a SQL query to select the name column from authors but convert all names to uppercase using the UPPER() function. Name the output column name_upper.
MySQL
Hint
Use SELECT UPPER(name) AS name_upper FROM authors; to convert names to uppercase.
3
Write a query to select author names in lowercase
Write a SQL query to select the name column from authors but convert all names to lowercase using the LOWER() function. Name the output column name_lower.
MySQL
Hint
Use SELECT LOWER(name) AS name_lower FROM authors; to convert names to lowercase.
4
Combine uppercase and lowercase queries
Write a SQL query to select the name column from authors and show two columns: one with names in uppercase called name_upper and one with names in lowercase called name_lower. Use UPPER() and LOWER() functions in the same query.
MySQL
Hint
Use SELECT UPPER(name) AS name_upper, LOWER(name) AS name_lower FROM authors; to show both columns.
Practice
(1/5)
1. What does the MySQL function UPPER('hello') return?
easy
A. 'heLLo'
B. 'hello'
C. 'Hello'
D. 'HELLO'
Solution
Step 1: Understand the UPPER function
The UPPER function converts all letters in the input text to uppercase letters.
Step 2: Apply UPPER to 'hello'
Applying UPPER to 'hello' changes all letters to uppercase, resulting in 'HELLO'.
Final Answer:
'HELLO' -> Option D
Quick Check:
UPPER('hello') = 'HELLO' [OK]
Hint: UPPER makes all letters capital [OK]
Common Mistakes:
Thinking UPPER only capitalizes first letter
Confusing UPPER with LOWER
Expecting mixed case output
2. Which of the following is the correct syntax to convert the column name to lowercase in a SELECT query?
easy
A. SELECT LOWER(name) FROM users;
B. SELECT LOWER name FROM users;
C. SELECT name.LOWER() FROM users;
D. SELECT LOWER[name] FROM users;
Solution
Step 1: Recall correct function syntax
MySQL functions use the format FUNCTION_NAME(argument), so LOWER(name) is correct.
Step 2: Check each option
SELECT LOWER(name) FROM users; uses correct syntax: LOWER(name). Options A, B, and D use invalid syntax forms.
Final Answer:
SELECT LOWER(name) FROM users; -> Option A
Quick Check:
Correct function call syntax = SELECT LOWER(name) FROM users; [OK]
Hint: Use function_name(column) syntax for MySQL functions [OK]
Common Mistakes:
Omitting parentheses around column
Using dot or bracket notation incorrectly
Writing function name in lowercase without parentheses
3. Given a table products with a column category containing values 'Books', 'electronics', 'TOYS', what will the query SELECT DISTINCT UPPER(category) FROM products; return?
medium
A. ['Books', 'electronics', 'TOYS']
B. ['BOOKS', 'ELECTRONICS', 'TOYS']
C. ['books', 'electronics', 'toys']
D. ['BOOKS', 'electronics', 'TOYS']
Solution
Step 1: Understand UPPER and DISTINCT
UPPER converts all text to uppercase. DISTINCT removes duplicates from the result set.
Step 2: Apply UPPER to each category value
'Books' -> 'BOOKS', 'electronics' -> 'ELECTRONICS', 'TOYS' -> 'TOYS'. All become uppercase.
Step 3: Collect distinct uppercase values
All three are unique after conversion, so the result is ['BOOKS', 'ELECTRONICS', 'TOYS'].
Final Answer:
['BOOKS', 'ELECTRONICS', 'TOYS'] -> Option B
Quick Check:
UPPER + DISTINCT = uppercase unique values [OK]
Hint: UPPER changes all letters; DISTINCT removes duplicates [OK]
Common Mistakes:
Expecting original case values
Ignoring DISTINCT effect
Mixing uppercase and lowercase in output
4. Consider the query: SELECT LOWER('MySQL') FROM dual. It returns an error. What is the likely cause?
medium
A. The table 'dual' does not exist in MySQL by default
B. LOWER function is not supported in MySQL
C. The string 'MySQL' must be in uppercase already
D. Missing semicolon at the end of the query
Solution
Step 1: Understand the use of 'dual'
'dual' is a special table in Oracle but not present by default in MySQL.
Step 2: Check MySQL behavior
MySQL does not require 'FROM dual' for selecting expressions; using it causes an error if 'dual' table is missing.
Final Answer:
The table 'dual' does not exist in MySQL by default -> Option A
Quick Check:
MySQL lacks default 'dual' table [OK]
Hint: MySQL doesn't need 'FROM dual' for expressions [OK]
Common Mistakes:
Assuming 'dual' exists like in Oracle
Thinking LOWER is unsupported
Blaming missing semicolon
5. You want to find all users in the users table whose email ends with '@example.com', ignoring case differences. Which query correctly uses UPPER or LOWER to achieve this?
hard
A. SELECT * FROM users WHERE LOWER(email) LIKE '%@Example.com';
B. SELECT * FROM users WHERE LOWER(email) LIKE '%@EXAMPLE.COM';
C. SELECT * FROM users WHERE UPPER(email) LIKE '%@EXAMPLE.COM';
D. SELECT * FROM users WHERE email LIKE '%@example.com';
Solution
Step 1: Understand case-insensitive matching
To ignore case, convert both sides to the same case before comparing.
Step 2: Apply UPPER to email and pattern
Using UPPER(email) and matching with uppercase pattern '%@EXAMPLE.COM' ensures case-insensitive match.
Step 3: Check options
SELECT * FROM users WHERE UPPER(email) LIKE '%@EXAMPLE.COM'; correctly uses UPPER on email and uppercase pattern. SELECT * FROM users WHERE LOWER(email) LIKE '%@Example.com'; mismatches case in pattern. SELECT * FROM users WHERE email LIKE '%@example.com'; is case-sensitive. SELECT * FROM users WHERE LOWER(email) LIKE '%@EXAMPLE.COM'; mismatches case in pattern.
Final Answer:
SELECT * FROM users WHERE UPPER(email) LIKE '%@EXAMPLE.COM'; -> Option C
Quick Check:
Match cases on both sides using UPPER or LOWER [OK]
Hint: Match cases on both sides with UPPER or LOWER [OK]
Common Mistakes:
Not matching case of pattern and column
Assuming LIKE is case-insensitive by default
Mixing LOWER with uppercase pattern
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.