GROUP_CONCAT multiple fields with a different delimiter

Is it possible to do something like:

GROUP_CONCAT(user, price SEPARATOR ', ') AS items

Result John3.99, Mike24.99

I need something like:

John - 3.99, Mike - 24.99

Basically use a different type of delimiter for the price field.

+4
source share
2 answers
GROUP_CONCAT(CONCAT(user, ' - ', price) SEPARATOR ', ') AS items

Or simply

GROUP_CONCAT(user, ' - ', price SEPARATOR ', ') AS items
+8
source

Try this way

GROUP_CONCAT(
  DISTINCT CONCAT(user,',',Price SEPERATOR) 
  ORDER BY items 
  SEPARATOR ';'
)
0
source

Source: https://habr.com/ru/post/1650472/


All Articles