-1

I need your help. I have 2 table.

1.company_classifications

company_name-classifications

Company A-1,2,3

Company B-1,2

2.classifications

id-name

1-Music 

2-Technologi

3-Food

I need query for result like this :

company_name-classification_name

Company A-Music, Technologi, Food   

Company B-Music, Food
AFD
  • 1,341
  • 2
  • 9
  • 8
  • 3
    See [Is storing a delimited list in a database column really that bad?](http://stackoverflow.com/a/3653574) – eggyal Jul 12 '13 at 16:24
  • If you have multiple values in one column for one row, you need to normalise your database. However, you need to work on your question before I can read it and help you. – Jodrell Jul 12 '13 at 16:25
  • @eggyal, er yes (I know you know that). – Jodrell Jul 12 '13 at 16:25
  • `FIND_IN_SET()` can help you on this but normalization is the best way to do. – John Woo Jul 12 '13 at 16:27
  • @eggyal,@Jodrell Ya, i know that. but the structure values i have from my client. – AFD Jul 12 '13 at 16:28
  • http://en.wikipedia.org/wiki/Third_normal_form, the concept was formalised by Codd in 1971 but still ... – Jodrell Jul 12 '13 at 16:28

1 Answers1

0
select cc.company_name,group_concat(c.name)
from company_classifications cc 
inner join classifications c 
on c.id = find_in_set(c.id,cc.classifications)
group by cc.company_name;

fiddle

Praveen Prasannan
  • 7,093
  • 10
  • 50
  • 70