0

I have a field in a mysql table that holds a comma separated group of numbers (ex 1,2,3,4,5). I'm trying to figure out the best way to query the table (especially if there are millions of rows) quickly with minimal cpu usage.

I could to the following easy enough:

select * from table where field like '%60,%';

However I don't think this is optimal, also it would return matches for field values such as 1,2,3,4,160. I did consider putting a comma at the beginning and end of the string such as ,1,2,3,4,160, and then the following query would work:

select * from table where field like '%,60,%';

Anyone have any ideas on the best way to do this?

Joe
  • 1,762
  • 9
  • 43
  • 60
  • This question is like this: [http://stackoverflow.com/questions/738133/comma-separated-values-in-a-database-field][1] [1]: http://stackoverflow.com/questions/738133/comma-separated-values-in-a-database-field – Jon Friskics May 11 '12 at 00:03
  • That question brought up FIND_IN_SET which seems to be what I need though I'm not sure of it's performance over millions of records. I'll monitor this question in case someone else posts a better solution. – Joe May 11 '12 at 00:16

0 Answers0