Question : store comma separated multiple numbers in a mysql database field database and query them efficiently

  I am building a product catalog, and basically I have 2 tables, the first is a 'drill-down' type category selector that does make/model/year like so:

1|Ford|Mustang|GT|1985|2003|Air Filter
2|Ford|Mustang|GT|1985|2003|Exhaust
3|Ford|Mustang|V6|1985|2003|Air Filter

And then a product table that has items like so - with the last field being the categories it corresponds to:

133391-A|Fram|Air Filter|1,2,3

the last column being the fitments. Basically one product can fit an unlimited number of applications, so my question is - what is the best way to store this info and search it? I know I can setup a varchar/text field and store a comma separated list of categories (as exemplified above). Is there a better way to do this? It's not really search friendly.

I guess my question is how do I store a list of numbers in a mysql table field and be able to search for the individual numbers (i.e. how do I search for '13' only when the field contains 1,7,5,26,44,119,226,1013,13 ?).

Thanks in advance; if I am going about this all wrong please let me know.

Answer : store comma separated multiple numbers in a mysql database field database and query them efficiently

You should have a link table between the product to the category.  This way, you can index the product and category in that table to facilitate fast efficient searches.

Product -
133391-A|Fram|Air Filter

Category -
1|Ford|Mustang|GT|1985|2003|Air Filter
2|Ford|Mustang|GT|1985|2003|Exhaust
3|Ford|Mustang|V6|1985|2003|Air Filter

Product_Category -
133391|1
133391|2
133391|3

Now you can search the Product_Category for all products that satisfy category 3, for example

Select Product.*
From Product_Category
inner join Product on Product.Product_ID = Product_Category.Product_ID
Where Product_Category.Category_ID = 3
Random Solutions  
 
programming4us programming4us