Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I replace all my NULL values in a particular field in a particular table?

I've looked all over the internet for my answer, and perhaps I'm just doing things wrong. I have a column in my MySQL table that I need to replace all the NULL values with a text string in my SQL Query using phpMyAdmin. I don't want the output to come out that way, I want to actually replace the null values with the text string.

I've tried

UPDATE `tablename` SET fieldname = replace (fieldname, "", "textstring")

I've read up on

SELECT ISNULL(field,"replacetext)

But this only shows the output, but doesn't actually replace it in the table.

I can't figure this out, and I've wasted so much time trying to find an answer.

like image 862
Valerie Avatar asked Jan 07 '11 19:01

Valerie


People also ask

How do you replace all NULL values?

The ISNULL Function is a built-in function to replace nulls with specified replacement values. To use this function, all you need to do is pass the column name in the first parameter and in the second parameter pass the value with which you want to replace the null value.

How do you replace NULL values in SQL with data?

We can replace NULL values with a specific value using the SQL Server ISNULL Function. The syntax for the SQL ISNULL function is as follow. The SQL Server ISNULL function returns the replacement value if the first parameter expression evaluates to NULL.

How do you replace NULL values in a string in SQL?

There are two ways to replace NULL with blank values in SQL Server, function ISNULL(), and COALESCE(). Both functions replace the value you provide when the argument is NULL like ISNULL(column, '') will return empty String if the column value is NULL.


2 Answers

update tablename set fieldname = "textstring" where fieldname is null;
like image 195
Nylon Smile Avatar answered Oct 04 '22 21:10

Nylon Smile


Have you tried

UPDATE `tablename` SET fieldname = '' where fieldname is null
like image 36
Raj Avatar answered Oct 04 '22 21:10

Raj