1Z0-909 · Question #52
You must write a statement that combines the first_name and last_name columns from the employees table as "last_name, first_name." Which two statements will do this?
The correct answer is B. SELECT CONCAT_WS(', ',last_name,first_name) FROM employees; E. SELECT CONCAT(last name,', ',first_name) FROM employees. Options B and E are correct because both properly use string concatenation functions to combine columns in the required "last_name, first_name" format. CONCAT(last_name, ', ', first_name) explicitly joins the three pieces in order, while CONCAT_WS(', ', last_name, first_name)…
Question
You must write a statement that combines the first_name and last_name columns from the employees table as "last_name, first_name." Which two statements will do this?
Options
- ASELECT last_name + ', ' + first_name FROM employees;
- BSELECT CONCAT_WS(', ',last_name,first_name) FROM employees;
- CSELECT GROUP_CONCAT(last_name, first_name) FROM employees;
- DSELECT last_name, ` , ',first_name FROM employees;
- ESELECT CONCAT(last name,', ',first_name) FROM employees;
How the community answered
(30 responses)- A13% (4)
- B77% (23)
- C7% (2)
- D3% (1)
Explanation
Options B and E are correct because both properly use string concatenation functions to combine columns in the required "last_name, first_name" format. CONCAT(last_name, ', ', first_name) explicitly joins the three pieces in order, while CONCAT_WS(', ', last_name, first_name) achieves the same result using a separator as its first argument - a cleaner option when joining many fields with the same delimiter.
Option A is wrong because + is the arithmetic addition operator in MySQL/standard SQL - it won't concatenate strings the way it does in SQL Server. Option C is wrong because GROUP_CONCAT is an aggregate function that merges values across rows, not across columns within a single row. Option D is wrong due to a syntax error - the mismatched backtick and quotes make it invalid, and the bare comma would return two separate columns rather than one combined string.
Memory tip: Think of CONCAT as "list everything to join," and CONCAT_WS as "set the separator once, then list the values" - the WS stands for With Separator. If you see GROUP_CONCAT, think grouping/aggregation, not column merging.
Topics
Community Discussion
No community discussion yet for this question.