Is it possible to find fields that have specified characters NEAR each other?

Discussion in 'MySQL' started by Leo727, Oct 22, 2009.

  1. #1
    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
     
    Leo727, Oct 22, 2009 IP
  2. heavydev

    heavydev Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could use the REGEXP comparison operator with MySQL.
    I can't guarantee it'll be fast, but it'll work.
     
    heavydev, Oct 23, 2009 IP
  3. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #3
    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.
     
    mastermunj, Oct 23, 2009 IP
  4. heavydev

    heavydev Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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.
     
    heavydev, Oct 23, 2009 IP
  5. Leo727

    Leo727 Active Member

    Messages:
    161
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    60
    #5
    It works! Thanks, very much appreciated :)
     
    Leo727, Oct 29, 2009 IP