Mysql make all uppercase letters lowercase in a column

Discussion in 'MySQL' started by Astroman, Aug 1, 2008.

  1. #1
    Is there a Mysql command to make all the letters in a column lowercase?

    I have some names of places like London, Berlin, Prague etc and I've decided I want them written london, berlin and prague - and thought there must be a way to do it all at once?

    I tried this but it didn't work:

    SELECT LCASE(column_name) FROM `table_name`
     
    Astroman, Aug 1, 2008 IP
  2. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #2
    I assume that you want the names stored in lowercase. If so, you need to UPDATE the columns. The SELECT statement simply returns the rows to the client, but leaves the contents unchanged.
     
    Social.Network, Aug 1, 2008 IP
  3. wootty

    wootty Peon

    Messages:
    447
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you actually want to update that column, then something along the lines of:

    update table_name set col_name = LOWER(col_name);

    should work i think.
     
    wootty, Aug 1, 2008 IP
    Astroman likes this.
  4. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #4
    This query will work only whenever you select the name, but it will update it in the table.

    You can do as wootty suggested or use LCASE() in the same fashion
    UPDATE table_name SET col_name = LCASE(col_name);
    Code (markup):
    Now you can select the name in lowercase like
    SELECT column_name FROM `table_name`
    Code (markup):
     
    mwasif, Aug 1, 2008 IP
    Astroman likes this.
  5. Astroman

    Astroman Well-Known Member

    Messages:
    2,355
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    135
    #5
    Thanks, I should have known that but I have such a blind spot for database stuff, my brain just freezes over. :)

    Added rep to you both. :)
     
    Astroman, Aug 2, 2008 IP