Recall & Review
beginner
What does the CONCAT function do in SQL?
CONCAT joins two or more strings together into one string.
Click to reveal answer
beginner
How is CONCAT_WS different from CONCAT?
CONCAT_WS joins strings with a separator between them. The 'WS' means 'With Separator'.
Click to reveal answer
intermediate
What happens if CONCAT receives a NULL value as one of its arguments?
CONCAT treats NULL as an empty string and continues joining other strings.
Click to reveal answer
beginner
What is the first argument in CONCAT_WS?
The first argument in CONCAT_WS is the separator string used between other strings.
Click to reveal answer
beginner
Write a simple SQL example using CONCAT_WS to join 'apple', 'banana', and 'cherry' with a comma and space.
SELECT CONCAT_WS(', ', 'apple', 'banana', 'cherry'); -- Result: 'apple, banana, cherry'
Click to reveal answer
What does CONCAT('Hello', ' ', 'World') return?
✗ Incorrect
CONCAT joins all strings exactly as given, so it returns 'Hello World' including the space.
Which function allows you to specify a separator between strings?
✗ Incorrect
CONCAT_WS lets you specify a separator as the first argument.
If one argument in CONCAT is NULL, what happens?
✗ Incorrect
CONCAT treats NULL as empty string and continues concatenation.
What is the output of CONCAT_WS('-', '2024', NULL, '06', '15')?
✗ Incorrect
CONCAT_WS skips NULL values and places the separator only between non-null strings.
Which of these is a valid use of CONCAT_WS?
✗ Incorrect
The first argument is the separator, so ' ' is correct as separator. Using only one string or NULL values is valid; NULLs are skipped.
Explain how CONCAT and CONCAT_WS work and how they handle NULL values.
Think about how you join words in a sentence with or without spaces.
You got /4 concepts.
Write an example SQL query using CONCAT_WS to join first name, middle name, and last name with spaces, skipping NULL middle name.
Remember CONCAT_WS ignores NULL values automatically.
You got /3 concepts.