Björn C
Björn C

Reputation: 4008

mySQL Export Excel with concated data

I'd like a custom export file from mySQL.

I have a table:

name .   number .   class
--------------------------------
name1 .  100 .      1
name2 .  101 .      3
name1 .  100 .      5

Now i'd like to export this data into a excel file.
But where it is duplicate number i'd like to concat the class data.
Output from table above would be:

name1    100  1 5
name2    101  3

The classes should be seperated with whitespace.

Is this possible?

Maby i have to create another table and concat the data in the first step, and later export that table?

Upvotes: 0

Views: 44

Answers (1)

Aishwarya
Aishwarya

Reputation: 433

Use GROUP_CONCAT

SELECT name, number,GROUP_CONCAT(class SEPARATOR ' ') FROM table1 GROUP BY name

Upvotes: 2

Related Questions