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  
  •  replace cells in database from another database. keep all other cells in record the same.
  •  Regular Expression to match 7697998997 or 8724550
  •  Using Key Management Services for WS 2008 in an SBS 2003 environment.
  •  Can't install Sharepoint svcs on Server 2008 because can't install DotNet3 because "You must use the role management tool to install...microsoft .net framework". ... WHAT?!?
  •  Actionscript 3: FileReference save error
  •  Jquery ui modal and using form in the pop up window.
  •  Make a cell show drop-down list IF a certain value in another cell?
  •  Can flash CS5 work with real 3d models like models from Blender or 3D Studio Max?
  •  Closing Quickbooks 2007 results in a .NET Broadbast Event Window Error
  •  Wordpress plugin TinyMCE Advanced not working and I'm getting 404 Reports from wp-includes tinymce files
  •  
    programming4us programming4us