I have field called features as i am storing the value as comma separated values, now while selecting i need to fetch the corresponding name of the comma separated vale
table1- feature
id feature_names
1 A
2 B
3 C
4 D
5 E
table2- car
id car feature_ids
1 Zen 2,3,4 // features = B,C,D
2 Benz 1,2 // features = A,B
3 Audi 4,5 // features = D,E
How to get the corresponding names of the comma separated values while selecting the car table?
Redesign your database.
After that, you can use a
JOINin your query. Something like this:You should not use comma-separated fields like that in relational databases. Certainly not, if you want to write queries based on that field. Even if it seems to work, it will quickly become extremely inefficient and unmaintainable.
Your scenario is called a Many-to-many relationship between the tables – cars can have any features and a feature can belong to any cars. The technique I outlined is called Cross-reference table. I have given all the keywords for you to search for the right MySQL tutorials and articles, for example: