130

I have a MySQL database of keywords that are presently mixed-case. However, I want to convert them all to lowercase. Is there an easy command to do this, either using MySQL or MySQL and PHP?

Thomas Owens
  • 111,344
  • 96
  • 305
  • 429
  • I guess you're also using a dump from a friend who thought it would be a good idea to store usernames with capitalized letters. – Buffalo Jul 04 '13 at 15:46

9 Answers9

259
UPDATE table SET colname=LOWER(colname);
Paul Dixon
  • 287,944
  • 49
  • 307
  • 343
  • if the collation of a column is set to `ascii_bin`, wont this automatically convert everything to lowercase or am i mistaken? – oldboy Jul 29 '19 at 01:01
29

Yes, the function is LOWER() or LCASE() (they both do the same thing).

For example:

select LOWER(keyword) from my_table
Jon Grant
  • 11,155
  • 2
  • 34
  • 56
12

SELECT LOWER(foo) AS foo FROM bar

Greg
  • 307,243
  • 53
  • 363
  • 328
9

You can use the functions LOWER() or LCASE().

These can be used both on columns or string literals. e.g.

SELECT LOWER(column_name) FROM table a;

or

SELECT column_name FROM table a where column = LOWER('STRING')

LCASE() can be substituted for LOWER() in both examples.

dmanxiii
  • 49,767
  • 10
  • 31
  • 23
5

Did you try looking it up? Google, manual...

http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_lower

mysql> SELECT LOWER('QUADRATICALLY');
        -> 'quadratically'
myplacedk
  • 1,534
  • 2
  • 14
  • 19
3

Simply use:

UPDATE `tablename` SET `colnameone`=LOWER(`colnameone`);  

or

UPDATE `tablename` SET `colnameone`=LCASE(`colnameone`);

Both functions will work the same.

dferenc
  • 7,637
  • 12
  • 39
  • 46
Vi8L
  • 848
  • 9
  • 11
0

Interesting to note that the field name is renamed and if you reference it in a function, you will not get its value unless you give him an alias (that can be its own name)

Example: I use a function to dynamically get a field name value:

function ColBuilder ($field_name) {
…
While ($result = DB_fetch_array($PricesResult)) {
$result[$field_name]
}
…
}

my query being: SELECT LOWER(itemID), … etc..

needed to be changed to: SELECT LOWER(itemID) as itemID, … etc..

-3

use LOWER function to convert data or string in lower case.

select LOWER(username) from users;

or

select * from users where LOWER(username) = 'vrishbh';
uma
  • 2,814
  • 24
  • 20
-6

I believe in php you can use

strtolower() 

so you could make a php to read all the entries in the table then use that command to print them back as lower case

Rodent43
  • 161
  • 1
  • 3