Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update all values of a column to lowercase

Tags:

mysql

Lets say I have something like this

uid    tag
1      HeLLo
2      heLLO
3      HELLO
4      hello

How can I update all values in the "tag" column to:

uid    tag
1      hello 
2      hello 
3      hello 
4      hello 

using MySQL?

like image 435
Adam Ramadhan Avatar asked May 28 '11 09:05

Adam Ramadhan


People also ask

How do you update all values in a column?

First, specify the table name that you want to change data in the UPDATE clause. Second, assign a new value for the column that you want to update. In case you want to update data in multiple columns, each column = value pair is separated by a comma (,). Third, specify which rows you want to update in the WHERE clause.

What is the SQL syntax to change all column data to lowercase?

The LOWER() function converts a string to lower-case.

How do you change all caps to lowercase in SQL?

How to Convert Uppercase to Lowercase in SQL Server – LOWER() In SQL Server, you can convert any uppercase string to lowercase by using the LOWER() function. Simply provide the string as an argument when you call the function, and it will be returned in lowercase form.

How do you do case insensitive comparison in SQL?

To do a case-insensitive comparison, use the ILIKE keyword; e.g., column ILIKE 'aBc' and column ILIKE 'ABC' both return TRUE for 'abc' . In contrast, MySQL and MS SQL Server have case-insensitive behaviors by default. This means WHERE column = 'abc' returns TRUE for e.g., 'abc' , 'ABC' , or 'aBc' .


4 Answers

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

UPDATE table_name SET tag = LOWER(tag)
like image 165
Rippo Avatar answered Oct 06 '22 00:10

Rippo


LOWER()

update table set tag = LOWER(tag)
like image 29
Shakti Singh Avatar answered Oct 06 '22 01:10

Shakti Singh


Version for case-insensitive matching and including a "WHERE" clause if you don't want to update the entire column:

UPDATE table 
SET tag = LOWER(tag)
WHERE LOWER(tag) != tag
COLLATE Latin1_General_CS_AS

The COLLATE line will make it work if your database uses case insensitive matching, as mine does.

like image 35
Susie Avatar answered Oct 05 '22 23:10

Susie


Try this:

update `table` set `column_name` = LOWER(column_name without quotation)
like image 42
Anjani Barnwal Avatar answered Oct 06 '22 00:10

Anjani Barnwal