shashank
shashank

Reputation: 566

How to use Group_Concat() to concat in MySql

I have table structure like this-

 Code         Codelang          Name

  14           de              David
  14           en              Michel
  14           es              John

I want to show this table as-

 Code                Name

 14               [:de]David[:en]Michel[:es]John[:]

Is it possible to do this using Group_Concat() or is there any other way to do this.?

Upvotes: 0

Views: 381

Answers (1)

Alex
Alex

Reputation: 17289

SELECT
  code,
  GROUP_CONCAT(CONCAT('[:',codelang,']',name) SEPARATOR '') as name
FROM table1
GROUP BY code

to get [:] at the end you can try:

SELECT
  code,
  CONCAT(GROUP_CONCAT(CONCAT('[:',codelang,']',name) SEPARATOR ''),'[:]') as name
FROM table1
GROUP BY code

Upvotes: 1

Related Questions