2

I have used FIND_IN_SET to my below select sql query and got the result but I want to store industrie_branch comma separated list

Select Query:

SELECT i.instagrammer_id
      , CONCAT(i.first_name,' ',i.last_name) AS instagrammer_name
      , FLOOR(DATEDIFF (NOW(), i.date_of_birth)/365) AS age
      , i.date_of_birth
      , i.gender
      , i.email
      , i.created_date
      , b.name_en AS industrie_branch
FROM instagrammer AS i
LEFT JOIN industries_branches b ON FIND_IN_SET(b.industrie_branch_id, i.industrie_branch)
WHERE i.status = 1
ORDER BY instagrammer_name DESC

and getting this output of above query:

instagrammer_id     instagrammer_name       age     date_of_birth       gender      email               industrie_branch
***************     *****************       ***     *************       ******      ****************    ****************
37                  Jack                    27      1988-09-30          male        jack@hotmail.com    Food
37                  Jack                    27      1988-09-30          male        jack@hotmail.com    Photography
38                  Tom                     27      1988-09-30          male        tom@gmail.com       Lifestyle
38                  Tom                     27      1988-09-30          male        tom@gmail.com       Luxury

but I want this output with comma separated list for industrie_branch:

instagrammer_id     instagrammer_name       age     date_of_birth       gender      email               industrie_branch
***************     *****************       ***     *************       ******      ****************    ****************
37                  Jack                    27      1988-09-30          male        jack@hotmail.com    Food, Photography
38                  Tom                     27      1988-09-30          male        tom@gmail.com       Lifestyle, Luxury
Strawberry
  • 33,750
  • 13
  • 40
  • 57
Mr.Happy
  • 2,639
  • 9
  • 40
  • 73

1 Answers1

1

use it like this with GROUP_CONCAT

SELECT i.instagrammer_id
  , CONCAT(i.first_name,' ',i.last_name) AS instagrammer_name
  , FLOOR(DATEDIFF (NOW(), i.date_of_birth)/365) AS age
  , i.date_of_birth
  , i.gender
  , i.email
  , i.created_date
  , GROUP_CONCAT(b.name_en) AS industrie_branch
FROM instagrammer AS i
LEFT JOIN industries_branches b ON FIND_IN_SET(b.industrie_branch_id, i.industrie_branch)
WHERE i.status = 1
GROUP BY i.instagrammer_id
ORDER BY instagrammer_name DESC
Arun Krish
  • 2,153
  • 1
  • 10
  • 15