ilhan
ilhan

Reputation: 8995

How do you update a field if it is null in MySQL?

I have a field named size. Some rows are null. I want to update these rows' size field to 0. How I'll do it?

Upvotes: 2

Views: 103

Answers (4)

PermGenError
PermGenError

Reputation: 46438

UPDATE TABLENAME 
SET SIZE=0
WHERE SIZE IS NULL;

Upvotes: 0

Darren
Darren

Reputation: 70796

UPDATE TABLENAME
SET size = 0
WHERE size IS NULL

Upvotes: 3

newfurniturey
newfurniturey

Reputation: 38456

You'll have to use WHERE size IS NULL in the update clause:

UPDATE table SET size = 0 WHERE size IS NULL;

Upvotes: 2

Vishwanath Dalvi
Vishwanath Dalvi

Reputation: 36671

update tablename
set    size = 0
where  size is null;

Upvotes: 3

Related Questions