2
Table `names`
ID | name 
---------
1  | Alex
2  | John
3  | Alex
4  | Alex
5  | Alice
6  | Monica

SELECT `name` FROM `names` GROUP BY `name`
Alex
John
Alice
MOnica

so, I need to make like this

SELECT `name`, COMBINE_STRING(`ID`, SEPARATOR `,`) AS `IDS` FROM `names` GROUP BY `name`

and the result should be like this : 

and the result will be like this :

NAME | IDS
------------
Alex   1,3,4
John   2
Alice  5
MOnica 6

but as you see that mysql function COMBINE_STRING doesn't exist, so any ideas how to do this?

Aleksandr Sasha
  • 168
  • 1
  • 12

2 Answers2

1

Change COMBINE_STRING to group_concat so it becomes

SELECT `name`, group_concat(`ID`) AS `IDS` FROM `names` GROUP BY `name`

, is default separator for the group_concat when explicitly not provided.

Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63
0

Simply you can use GROUP_CONCAT function of MySql which'll work for you as like of your COMBINE_STRING

SELECT `name`, GROUP_CONCAT(`ID`) AS `IDS` FROM `names` GROUP BY `name`
Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54