GROUP_CONCAT Function in SQL
Level 4115 keystrokes
GROUP_CONCAT joins the values of a group into one string, here one list of member names per department.
SQL code
-- Return each department and a list of its members1SELECT2 department, -- GROUP_CONCAT joins the names of all rows in the group into one string3 GROUP_CONCAT(4 name -- Order the names alphabetically inside the list5 ORDER BY name -- Separate names with ', ' (the default is a comma without a space)6 SEPARATOR ', ' -- The result is cut at group_concat_max_len (1024 bytes by default)7 ) AS members8FROM9 employees-- One group, and one result row, per department; the row order is not guaranteed without ORDER BY10GROUP BY11 department;Output
+------------+---------------------+ | department | members | +------------+---------------------+ | HR | Alice, Bob | | IT | Carol, Dave, Eve | | Sales | Frank | +------------+---------------------+ 3 rows in set
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this SQL code and how often they appear.
,× 2'× 2_× 1;× 1(× 1)× 1