removing or working around space...

Discussion in 'MySQL' started by pHrEaK, Jun 21, 2011.

  1. #1
    I've recently entered a couple thousand records into a database. What I'm doing is creating a searchable database for a companies catalog. What has happened is that some of my records have space " " in front of or behind a string of text (or you may say my string includes space). For example in the database table under one field i have a record " LS46". Whenever a query is run to compare an input to see if it equals "LS46" the query says no that's not what I'm looking for and goes onto the next record. What would be the easiest way to work around or remove this space without going into phpMyAdmin and manually editing 2000 records?????
     
    pHrEaK, Jun 21, 2011 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Not sure on the column name, but try something like this.

    UPDATE my_table SET record_column = TRIM(record_column);

    Then make sure whatever method you use to populate entries strips off all white space before the record is added.

    Also, shouldn't be a problem, but make sure you make a backup of the existing data before running this or any query that affects the entire table.
     
    jestep, Jun 22, 2011 IP
  3. pHrEaK

    pHrEaK Active Member

    Messages:
    147
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Thank you very much that worked perfect. You saved me ample time my good friend!
     
    pHrEaK, Jun 22, 2011 IP