0
0
MySQLquery~5 mins

CONCAT and CONCAT_WS in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A'MySQL'
B'My SQL'
C'My NULL SQL'
DNULL
Which function allows you to specify a separator between strings?
ACONCAT_WS
BCONCAT
CCONCAT_SEP
DCONCAT_SEPARATOR
What does CONCAT_WS('-', '2024', NULL, '06') return?
A'2024-06'
B'2024--06'
C'2024-NULL-06'
DNULL
How many arguments does CONCAT_WS require at minimum?
AThree
BOne (separator only)
CTwo (separator and at least one string)
DNone
Which of these is a valid use of CONCAT to join 'Hello' and 'World'?
ACONCAT('Hello' + 'World')
BCONCAT('Hello', ' ', 'World')
CCONCAT_WS(' ', 'Hello', 'World')
DCONCAT('Hello' & 'World')
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.