how to insert into column value if column =NULL I have table 'board' with column 'name' some column has value , some has value NULL , I need insert in all column where is value = NULL
Asked
Active
Viewed 1,643 times
0
-
1Possible duplicate of [MySQL: update a field only if condition is met](http://stackoverflow.com/questions/14893355/mysql-update-a-field-only-if-condition-is-met) – Ullas Dec 05 '16 at 07:51
3 Answers
6
You don't need to insert, you need to update:
UPDATE board
SET name = 'some value'
WHERE name IS NULL

Tim Biegeleisen
- 502,043
- 27
- 286
- 360
2
Yes you need to update instead of insert.
If your value could also be a "NULL" value of type String then this might help
UPDATE board
SET name = 'value_to_be_inserted'
WHERE name IS NULL and upper(name) != "NULL"

Tom Taylor
- 3,344
- 2
- 38
- 63
-
-
If the value of null entered in the table is a string then "IS NULL" might miss... – Tom Taylor Dec 05 '16 at 07:55
0
Just an other perspective with CASE
expression.
Query
update `board`
set `name` = (
case when `name` is null then 'new value'
else `name` end
);

Ullas
- 11,450
- 4
- 33
- 50