Here is what I am trying to do : I would like a list of all records that have commas near each other in a certain field. For example, I would like to see all records where there are commas within 40 characters of each other in the field 'description'. I want to do it through a mysql query without php if possible... In case you are interested, my purpose is this : I have a database with a lot of user-contributed data, and in the description field they have often just typed a bunch of phrases separated by commas instead of a real description, so I'm hoping this query will help me to more quickly find these low-quality descriptions... Thanks for any tips you can provide Regards, Leo
You could use the REGEXP comparison operator with MySQL. I can't guarantee it'll be fast, but it'll work.
I tried several ways including splitting them in mysql function and then counting the gap between indexes of each comma. I believe it will be wise and better to use php for this problem.
no need to use php - a query like select * from field where description regexp ",.{1,40},"; Code (markup): this will find all descriptions with a comma, and between 1 and 40 characters between another comma. I have tested this with alphanumeric but not with commas but I'm fairly confident this will work for you.