Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Update Column value for all rows in Table where Column Value Is Null?

Still learning SQL-Fu, and trying to figure out how to do a simple update on my Table (ex. [TABLE1])to where all rows that have a [COST] column value of NULL are updated to a [COST] value of 0.00.

Can anyone show me how this is properly done? I've found examples for how to update EVERY row value for the column, but haven't quite been able to piece together the WHERE condition in a functional way.

like image 393
Analytic Lunatic Avatar asked Dec 17 '15 15:12

Analytic Lunatic

1 Answers

You can test for a NULL value in a column using IS NULL.

    SET cost = 0
    WHERE cost IS NULL;
like image 148
Joe Stefanelli Avatar answered Sep 24 '22 14:09

Joe Stefanelli