Forum Moderators: coopster

Message Too Old, No Replies

HOW TO: change null to something? (MySQL)

         

Ataraxia

4:43 pm on Oct 7, 2004 (gmt 0)

10+ Year Member



MySQL question:
How do I change _all_ of the records in the "username" field of my "links" table that are null to one value such as "Guest"?

I have tried these but they don's seem to do anything:

UPDATE links SET username=(REPLACE (username, '','Guest'));

UPDATE links SET username=(REPLACE (username, 'NULL','Guest'));

I think the problem is I don't know how to refer to a null. Help, please. (Thanks)

dmorison

4:44 pm on Oct 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You use "IS NULL" to refer to NULL values, so you need something like:

UPDATE links SET username='Guest' WHERE username IS NULL;

Ataraxia

4:46 pm on Oct 7, 2004 (gmt 0)

10+ Year Member



Note:

in this statement from the previous message it may not be obvious that there are two _single_ quotes in between Username and Guest parameters in this statement:

UPDATE links SET username=(REPLACE (username, '','Guest'));