Roma Sovach
Roma Sovach

Reputation: 35

INSERT INTO column if column = null

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

Upvotes: 0

Views: 1965

Answers (3)

Ullas
Ullas

Reputation: 11556

Just an other perspective with CASE expression.

Query

update `board`
set `name` = (
    case when `name` is null then 'new value'
    else `name` end
);

Upvotes: 0

Tom Taylor
Tom Taylor

Reputation: 3540

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"

Upvotes: 2

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520898

You don't need to insert, you need to update:

UPDATE board
SET name = 'some value'
WHERE name IS NULL

Upvotes: 6

Related Questions