Asia

MySQL GROUP_CONCAT function

Tudip

24 June 2016

Lets say there is a table named fictional_characters, that looks like:

id          id_novel               character_name
1          1100                        Harry
2          1100                        Ron
3          1100                        Hermione

4          1101                        Frodo
5          1101                        Sam

 
Time and again you want to display them like:
 
1100  Harry, Ron, Hermione
1101 Frodo, Sam

 

This can be handled directly in the DB by writing a query like:
 

SELECT  id_novel,
GROUP_CONCAT(character_name)
FROM  fictional_characters
GROUP BY id_novel;

Check the complete reference of GROUP_CONCAT at:
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

Tudip Technologies

Tudip Technologies is a value-driven Software Services company. We deliver excellence in dedicated and business-centric web solutions incorporated with innovation and expertise as the tools to achieve business goals. Our high-quality, cost-effective, reliable, and scalable services have helped us build an enduring relationship with our clients and customers.

Latest Posts

  • All Posts
  • Casestudy
  • Cloud
  • Healthcare
  • Ios
  • IOT
  • Java
  • Manufacturing
  • News
  • OTT
  • Supply Chain
  • Support and Maintainance
    •   Back
    • Banking

Related Posts

  • All Posts
  • Healthcare