Group Contact

Today, i am going to write first post for mySql. mySql has many functions to make programmer’s life easy.

When i was doing my project, i have to display some data by grouping with one field.

Example :

Suppose you have Student table with skill.

srno student skill
1 Jaydip PHP
2 Sanjay PHP
3 Jaydip Android
4 Pratik PHP
5 Sanjay CI
6 Pratik Magento

 

Now you want to display like student with all skills in one row.

srno student allskill
1 Jaydip PHP,Android
2 Sanjay PHP,CI
3 Pratik PHP,Magento

 

To get result like this, GROUP_CONTACT is there in mySql.

GROUP_CONTACT Query :

SELECT srno,student,GROUP_CONTACT(skill) AS allskill FROM student_skill GROUP BY user;