Recall & Review
beginner
What does the CONCAT function do in MySQL?
CONCAT joins two or more strings together into one string. For example, CONCAT('Hello', ' ', 'World') returns 'Hello World'.
Click to reveal answer
beginner
How is CONCAT_WS different from CONCAT?
CONCAT_WS adds a separator between strings while joining them. WS means 'With Separator'. For example, CONCAT_WS('-', '2024', '06', '15') returns '2024-06-15'.
Click to reveal answer
intermediate
What happens if one of the arguments in CONCAT is NULL?
If any argument in CONCAT is NULL, the whole result becomes NULL. For example, CONCAT('Hello', NULL, 'World') returns NULL.
Click to reveal answer
intermediate
How does CONCAT_WS handle NULL values?
CONCAT_WS skips NULL values and does not add separators for them. For example, CONCAT_WS('-', '2024', NULL, '15') returns '2024-15'.
Click to reveal answer
beginner
Write a query using CONCAT_WS to join first_name and last_name with a space.
SELECT CONCAT_WS(' ', first_name, last_name) AS full_name FROM users;
Click to reveal answer
What will CONCAT('My', NULL, 'SQL') return?
✗ Incorrect
CONCAT returns NULL if any argument is NULL.
Which function allows you to specify a separator between strings?
✗ Incorrect
CONCAT_WS stands for CONCAT With Separator.
What does CONCAT_WS('-', '2024', NULL, '06') return?
✗ Incorrect
CONCAT_WS skips NULL values and does not add extra separators.
How many arguments does CONCAT_WS require at minimum?
✗ Incorrect
CONCAT_WS needs a separator and at least one string to join.
Which of these is a valid use of CONCAT to join 'Hello' and 'World'?
✗ Incorrect
CONCAT joins strings directly; use commas to separate arguments.
Explain how CONCAT and CONCAT_WS handle NULL values differently.
Think about what happens when you join strings with missing parts.
You got /3 concepts.
Describe a real-life example where CONCAT_WS is more useful than CONCAT.
Consider formatting addresses or dates.
You got /3 concepts.