I would like to pass the SEPARATOR
value of a GROUP_CONTACT
as a variable (or function parameter), however this code will fail
SET @sep = ' ';
SELECT
`group`,
GROUP_CONCAT( `field` ORDER BY `idx` SEPARATOR @sep ) `fields`
FROM `table`
GROUP BY `group`;
I know I can do something like
SELECT
`group`,
SUBSTRING(
GROUP_CONCAT( CONCAT(`field`,@sep) ORDER BY `idx` SEPARATOR ''),
1,
LENGTH(
GROUP_CONCAT( CONCAT(`field`,@sep) ORDER BY `idx` SEPARATOR '')
)-LENGTH(@sep)
) `fields`
FROM `table`
GROUP BY `group`;
But it would be nicer to have a more concise syntax.
Edit:
SELECT
`group`,
SUBSTRING(
GROUP_CONCAT( CONCAT(@sep,`field`) ORDER BY `idx` SEPARATOR ''),
LENGTH(@sep)+1
) `fields`
FROM `table`
GROUP BY `group`;
Is a little simpler, but not satisfactory enough.