Knowledge Walls
John Peter
Pune, Maharashtra, India
How to use GROUP_CONCAT function in MYSQL with Examples
GROUP_CONCAT() Function 
Group concat function is used to join the columns with delimiter. By default it is taking comma(,) delimiter.

  •     Join columns data with delimiter
  •     Order by with joining data
  •     Distinct the joining data values.
User_info table has id and username columns. 
id  username
1  john
2  peter
3  raja
4  Peter
How to use GROUP_CONCAT() function
-- ouput
-- john,peter,raja,Peter
select group_concat(first_name) from user_info;

-- output
-- john,peter,raja
select group_concat(DISTINCT username) from user_info;

-- output
-- john|peter|raja|Peter
select group_concat(username SEPARATOR "|") from user_info;

-- output
-- john|peter|Peter|raja
select group_concat(username ORDER BY username desc SEPARATOR "|") from user_info;
Best Lessons of "One day One Thing to Know"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details