0
0
MySQLquery~20 mins

CONCAT and CONCAT_WS in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CONCAT Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of CONCAT with NULL values
What is the output of this MySQL query?
SELECT CONCAT('Hello', NULL, 'World');
MySQL
SELECT CONCAT('Hello', NULL, 'World');
ANULL
B'HelloWorld'
C'HelloNULLWorld'
D'Hello World'
Attempts:
2 left
💡 Hint
Remember how CONCAT treats NULL values in MySQL.
query_result
intermediate
2:00remaining
Using CONCAT_WS with NULL values
What is the output of this MySQL query?
SELECT CONCAT_WS('-', '2024', NULL, '06', '15');
MySQL
SELECT CONCAT_WS('-', '2024', NULL, '06', '15');
ANULL
B'2024-NULL-06-15'
C'2024--06-15'
D'2024-06-15'
Attempts:
2 left
💡 Hint
CONCAT_WS skips NULL values instead of treating them as strings.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in CONCAT usage
Which option contains a syntax error in using CONCAT in MySQL?
ASELECT CONCAT('A' 'B', 'C');
BSELECT CONCAT('A', , 'C');
CSELECT CONCAT('A', 'B' 'C');
DSELECT CONCAT('A', 'B', 'C');
Attempts:
2 left
💡 Hint
Look for missing arguments or commas.
optimization
advanced
2:00remaining
Optimizing string concatenation with CONCAT_WS
You want to concatenate first name, middle name, and last name with spaces between them. Middle name can be NULL. Which query is the most efficient and correct to avoid extra spaces?
ASELECT CONCAT(first_name, ' ', middle_name, ' ', last_name) FROM users;
BSELECT CONCAT(first_name, middle_name, last_name) FROM users;
CSELECT CONCAT_WS(' ', first_name, middle_name, last_name) FROM users;
DSELECT CONCAT_WS('', first_name, middle_name, last_name) FROM users;
Attempts:
2 left
💡 Hint
Think about how NULL values and separators are handled.
🧠 Conceptual
expert
2:00remaining
Behavior difference between CONCAT and CONCAT_WS
Which statement correctly describes the difference between CONCAT and CONCAT_WS in MySQL?
ACONCAT returns NULL if any argument is NULL; CONCAT_WS skips NULL arguments and does not return NULL.
BCONCAT_WS returns NULL if any argument is NULL; CONCAT skips NULL arguments.
CBoth CONCAT and CONCAT_WS return NULL if any argument is NULL.
DBoth CONCAT and CONCAT_WS skip NULL arguments and never return NULL.
Attempts:
2 left
💡 Hint
Think about how each function treats NULL values.