I have a following situation in my project. There are some tag values which are associated to a single category.
Example:
Fruits : Apple, Banana, Grape
Vegetables: Tomato, Cabbage, Brinjal
Now, for this I use a simple table in database with two columns, Category, Tag, and I store “Fruits” in Category column and “Apple, Banana, Grape” in Tag column (each tag separated by coma). And when I query a single Category using simple SQL statement like select tag from TagsCollection where category='Fruits'; I get a string with all the tags that belong to “Fruits” category. Note that the table will have only single instance of any particular Category as record. And than I need all the tags to be separated for further processing, so I split the string on comas in my programming language (Java, here).
Now, what can be an ideal way to implement something like this? do I proceed with RDBMS-way of storage (MySQL, to be precise) or is there any other faster way to store & retrieve such type of data.
Your current design violates first normal form, since you have multiple values in a single row of a single column. Also, any query on tag values is likely to perform poorly.
A normalised design would retain Category and Tag columns, but would have a separate row for each combination of Category and Tag – like so: