[SOLVED] mysql updating NULL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

[SOLVED] mysql updating NULL

Post by wtf »

Code: Select all

update table set column = 'value' where column = NULL

Code: Select all

update table set column = 'value' where column = 'NULL'

I can't get it to work! What's the trick???
Last edited by wtf on Mon Jan 23, 2006 11:48 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the first one would be it. Are you sure the column supports NULL values? Maybe it's a blank string instead?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Code: Select all

update `table` set `column` = 'value' where isnull(`othercolumn`) or `othercolumn` = ''
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

Are you sure the column supports NULL values? Maybe it's a blank string instead?

I tried blank string and it updated only blank fields, fields with NULL stayed untouched. Burrito's solution worked so it's all good.
Post Reply