0
0
SQLquery~20 mins

CONCAT and CONCAT_WS in SQL - 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
Consider the following SQL query:
SELECT CONCAT('Hello', NULL, 'World') AS result;

What will be the output of this query?
SQL
SELECT CONCAT('Hello', NULL, 'World') AS result;
ASyntax Error
B'Hello NULL World'
C'HelloWorld'
DNULL
Attempts:
2 left
💡 Hint
Remember how CONCAT handles NULL values in SQL.
query_result
intermediate
2:00remaining
Using CONCAT_WS with NULL values
What is the output of this SQL query?
SELECT CONCAT_WS('-', '2024', NULL, '06', '15') AS date_str;
SQL
SELECT CONCAT_WS('-', '2024', NULL, '06', '15') AS date_str;
A'2024-06-15'
B'2024--06-15'
C'2024-NULL-06-15'
DNULL
Attempts:
2 left
💡 Hint
CONCAT_WS skips NULL values when concatenating.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in CONCAT usage
Which of the following SQL statements will cause a syntax error?
ASELECT CONCAT('A', 'B', 'C') AS result;
BSELECT CONCAT('A', , 'C') AS result;
CSELECT CONCAT('A', NULL, 'C') AS result;
DSELECT CONCAT_WS('-', 'A', 'B', 'C') AS result;
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 produces the correct full name without extra spaces?
ASELECT CONCAT_WS(' ', first_name, middle_name, last_name) AS full_name FROM users;
BSELECT CONCAT_WS(' ', first_name, COALESCE(middle_name, ''), last_name) AS full_name FROM users;
CSELECT CONCAT(first_name, ' ', middle_name, ' ', last_name) AS full_name FROM users;
DSELECT CONCAT(first_name, middle_name, last_name) AS full_name FROM users;
Attempts:
2 left
💡 Hint
CONCAT_WS skips NULL values and adds separators only between non-NULL values.
🧠 Conceptual
expert
2:00remaining
Difference between CONCAT and CONCAT_WS behavior
Which statement correctly describes the difference between CONCAT and CONCAT_WS functions in SQL?
ABoth CONCAT and CONCAT_WS skip NULL arguments and add separators for them.
BCONCAT skips NULL arguments; CONCAT_WS returns NULL if any argument is NULL.
CBoth CONCAT and CONCAT_WS return NULL if any argument is NULL.
DCONCAT returns NULL if any argument is NULL; CONCAT_WS skips NULL arguments and does not add separators for them.
Attempts:
2 left
💡 Hint
Think about how each function treats NULL values and separators.