Collections:
GROUP_CONCAT() - Concatenating Items in Group
How to concatenate items of a field expression in result set groups using the GROUP_CONCAT() function?
✍: FYIcenter.com
GROUP_CONCAT(expr) is a MySQL built-in aggregate function that
concatenates items of a field expression in result set groups.
For example:
SELECT help_category_id, LEFT(GROUP_CONCAT(help_topic_id), 32) FROM mysql.help_topic GROUP BY help_category_id; -- +------------------+---------------------------------------+ -- | help_category_id | LEFT(GROUP_CONCAT(help_topic_id), 32) | -- +------------------+---------------------------------------+ -- | 1 | 0,1 | -- | 2 | 2,6,7,8,9,10,11,12,13,14,15,16,1... | -- | 3 | 3,618,619,620,621,622,623,624,62... | -- | 4 | 4,5 | -- | 5 | 40,43,44 | -- ... -- +------------------+---------------------------------------+
Reference information of the GROUP_CONCAT() function:
GROUP_CONCAT(DISTINCT expr ORDER BY order_list SEPARATOR delimiter): str Returns a string result with the concatenated non-NULL values from a group. It returns NULL if there are no non-NULL values. Arguments, return value and availability: expr: Required. The field expression in result set groups. DISTINCT: Optional. If provided, only distinct values of expr are used. ORDER BY order_list: Optional. If provided, items are sorted. SEPARATOR delimiter: Optional. Default is SEPARATOR ','. str: Return value. The concatenated string. Available since MySQL 5.7.
⇒ GROUPING() - Identifying Super-Aggregate Row
⇐ COUNT() - Counting Items in Group
2023-11-18, 917🔥, 0💬
Popular Posts:
How AdventureWorksLT tables are related in SQL Server? There are 12 user tables defined in Adventure...
How To Use "IF ... ELSE IF ..." Statement Structures in SQL Server Transact-SQL? "IF ... ELSE IF ......
How To Select All Columns of All Rows from a Table with a SELECT statement in SQL Server? The simple...
What Are Out-of-Range Errors with DATETIME values in SQL Server Transact-SQL? When you enter DATETIM...
How To Get the Definition of a Stored Procedure Back in SQL Server Transact-SQL? If you want get the...