1

I have a mysql table like below:

GROUP_CONCAT(Name)  Email

a,b,c               email1@gmail.com

My expected Output is :

Id    Name1  Name2   Name3  Email

1     A      B       C      email1@gmail.com

How to do that using mysql query.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nisanth
  • 323
  • 8
  • 24
  • 3
    The question how it is currently formulated is a possible duplicate: http://stackoverflow.com/questions/1096679/can-mysql-split-a-column – Thomas Oct 01 '15 at 05:25

1 Answers1

0

Below query may give idea what you are looking for --

SELECT SUBSTRING_INDEX(GROUP_CONCAT(Name), ' ', 1) AS fname,
SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(Name),' ', 2), ' ',-1) AS mname,
SUBSTRING_INDEX(GROUP_CONCAT(Name), ' ', -1) as lname , Email FROM mytable;
Abhishek
  • 1,543
  • 3
  • 13
  • 29
  • Thanks for your reply while i am using this query i am having the output like fname and mname and lname all having the a,b,c . how to solve this. – Nisanth Oct 01 '15 at 05:42
  • for all records is it showing the same data for these coulmns ? – Abhishek Oct 01 '15 at 05:44
  • yes . here i attach one link this one is i expected . How to split comma separated single column into multiple columns in php mysql see this question this one is i posted yesterday but i can't get clear answer – Nisanth Oct 01 '15 at 05:47
  • here is my output while i am running your query a,b,c a,b,c a,b,c email1@gmail.com – Nisanth Oct 01 '15 at 06:03
  • Basically your group concat query should provide the multiple rows, and then at that query should be fine, although I can see the provided question reference , you have not designed your database properly as there may be more than three or less than three no of needed coulmns. SO YOU MIGHT be NOT GOING in RIGHT DIRECTION --- http://stackoverflow.com/questions/32865945/how-to-split-comma-separated-single-column-into-multiple-columns-in-php-mysql – Abhishek Oct 01 '15 at 06:26