Bird
Raised Fist0
MySQLquery~10 mins

UPPER and LOWER in MySQL - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - UPPER and LOWER
Start with input string
↓
Convert all
↓
letters to
↓
uppercase
↓
Return converted string
↓
End
The flow starts with an input string, then chooses either UPPER or LOWER function to convert all letters to uppercase or lowercase, and finally returns the converted string.
Execution Sample
MySQL
SELECT UPPER('Hello World') AS upper_text,
       LOWER('Hello World') AS lower_text;
This query converts the string 'Hello World' to uppercase and lowercase, showing both results.
Execution Table
StepFunction CalledInput StringOutput String
1UPPER'Hello World''HELLO WORLD'
2LOWER'Hello World''hello world'
3END--
💡 Both functions processed the input string and returned the converted strings; execution ends.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
input_string'Hello World''Hello World''Hello World''Hello World'
upper_textNULL'HELLO WORLD''HELLO WORLD''HELLO WORLD'
lower_textNULLNULL'hello world''hello world'
Key Moments - 2 Insights
Why does the input string not change after calling UPPER or LOWER?
The input string remains unchanged because UPPER and LOWER return new converted strings without modifying the original input, as shown in execution_table steps 1 and 2.
Can UPPER and LOWER affect non-letter characters like spaces or numbers?
No, UPPER and LOWER only change letter characters; spaces, numbers, and symbols remain the same, which is why 'Hello World' keeps the space unchanged in the output.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output of UPPER at step 1?
A'HELLO WORLD'
B'hello world'
C'Hello World'
D'HELLO world'
💡 Hint
Check the Output String column in execution_table row with Step 1.
At which step does LOWER function produce its output?
AStep 1
BStep 2
CStep 3
DNo output produced
💡 Hint
Look at the Function Called column in execution_table to find when LOWER is called.
If the input string was '123 ABC xyz', what would LOWER('123 ABC xyz') return?
A'123 abc XYZ'
B'123 ABC XYZ'
C'123 abc xyz'
D'123 ABC xyz'
💡 Hint
LOWER converts letters to lowercase but leaves numbers unchanged, as seen in variable_tracker.
Concept Snapshot
UPPER(string) converts all letters in string to uppercase.
LOWER(string) converts all letters in string to lowercase.
Non-letter characters remain unchanged.
Both return new strings without modifying the original.
Use in SELECT to display converted text.
Full Transcript
This visual execution trace shows how the MySQL functions UPPER and LOWER work. Starting with the input string 'Hello World', the UPPER function converts all letters to uppercase, resulting in 'HELLO WORLD'. The LOWER function converts all letters to lowercase, resulting in 'hello world'. The input string itself does not change. Non-letter characters like spaces remain the same. The execution table tracks each step, showing the function called, input, and output. The variable tracker shows how variables change after each step. Key moments clarify common confusions, such as why the input string stays the same and how non-letter characters are unaffected. The quiz questions help reinforce understanding by referencing the execution visuals. The concept snapshot summarizes the key points for quick review.

Practice

(1/5)
1. What does the MySQL function UPPER('hello') return?
easy
A. 'heLLo'
B. 'hello'
C. 'Hello'
D. 'HELLO'

Solution

  1. Step 1: Understand the UPPER function

    The UPPER function converts all letters in the input text to uppercase letters.
  2. Step 2: Apply UPPER to 'hello'

    Applying UPPER to 'hello' changes all letters to uppercase, resulting in 'HELLO'.
  3. Final Answer:

    'HELLO' -> Option D
  4. 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

  1. Step 1: Recall correct function syntax

    MySQL functions use the format FUNCTION_NAME(argument), so LOWER(name) is correct.
  2. Step 2: Check each option

    SELECT LOWER(name) FROM users; uses correct syntax: LOWER(name). Options A, B, and D use invalid syntax forms.
  3. Final Answer:

    SELECT LOWER(name) FROM users; -> Option A
  4. 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

  1. Step 1: Understand UPPER and DISTINCT

    UPPER converts all text to uppercase. DISTINCT removes duplicates from the result set.
  2. Step 2: Apply UPPER to each category value

    'Books' -> 'BOOKS', 'electronics' -> 'ELECTRONICS', 'TOYS' -> 'TOYS'. All become uppercase.
  3. Step 3: Collect distinct uppercase values

    All three are unique after conversion, so the result is ['BOOKS', 'ELECTRONICS', 'TOYS'].
  4. Final Answer:

    ['BOOKS', 'ELECTRONICS', 'TOYS'] -> Option B
  5. 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

  1. Step 1: Understand the use of 'dual'

    'dual' is a special table in Oracle but not present by default in MySQL.
  2. Step 2: Check MySQL behavior

    MySQL does not require 'FROM dual' for selecting expressions; using it causes an error if 'dual' table is missing.
  3. Final Answer:

    The table 'dual' does not exist in MySQL by default -> Option A
  4. 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

  1. Step 1: Understand case-insensitive matching

    To ignore case, convert both sides to the same case before comparing.
  2. Step 2: Apply UPPER to email and pattern

    Using UPPER(email) and matching with uppercase pattern '%@EXAMPLE.COM' ensures case-insensitive match.
  3. 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.
  4. Final Answer:

    SELECT * FROM users WHERE UPPER(email) LIKE '%@EXAMPLE.COM'; -> Option C
  5. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard