0
0
SQLquery

CONCAT and CONCAT_WS in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A'Hello, World'
B'HelloWorld'
C'Hello-World'
D'Hello World'
Which function allows you to specify a separator between strings?
ACONCAT_WS
BLENGTH
CSUBSTRING
DCONCAT
If one argument in CONCAT is NULL, what happens?
AThe whole result is NULL
BNULL is treated as empty string
CAn error occurs
DNULL is converted to 'NULL' text
What is the output of CONCAT_WS('-', '2024', NULL, '06', '15')?
A2024--06-15
B2024NULL06-15
C2024-06-15
DNULL-2024-06-15
Which of these is a valid use of CONCAT_WS?
ACONCAT_WS(' ', 'Hello', 'World')
BCONCAT_WS('Hello', ' ', 'World')
CCONCAT_WS(' ', 'Hello')
DCONCAT_WS(' ', NULL)
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.