0

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.?

shashank
  • 566
  • 3
  • 10
  • 31
  • This is, at best, a very strange task to ask of the database. Perhaps it's a manipulation that you should perform in the presentation layer of your application (i.e. in the program code that accesses MySQL)? – eggyal Mar 04 '15 at 17:37

1 Answers1

1
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
Alex
  • 16,739
  • 1
  • 28
  • 51
  • hello thanks Alex for reply. using your code I am getting this- `[:de]David[:en]Michel[:es]John` it is missing `[:]` at the end. – shashank Mar 04 '15 at 18:03
  • What will be the mysql query if I want to copy this column data to another column.? I have got follwing structure after applying above query. `Code` `Nombre` `14` `[:de]David[:en]Michel[:es]John[:]` – shashank Mar 04 '15 at 18:29
  • I don't understand... why do you need data to be copied using sql? – Alex Mar 04 '15 at 18:31
  • Hey Alex Please check- http://stackoverflow.com/questions/28862294/what-will-be-right-mtsql-syntax-to-copy-a-column-data-to-another-column – shashank Mar 04 '15 at 18:39