Ho to do this? What query can be written by using select statement where all nulls should be replaced with 123?
I know we can do this y using, update tablename set fieldname = "123" where fieldname is null;
but can't do it using select statement.
Ho to do this? What query can be written by using select statement where all nulls should be replaced with 123?
I know we can do this y using, update tablename set fieldname = "123" where fieldname is null;
but can't do it using select statement.
You have a lot of options for substituting NULL values in MySQL:
select case
when fieldname is null then '123'
else fieldname end as fieldname
from tablename
select coalesce(fieldname, '123') as fieldname
from tablename
select ifnull(fieldname, '123') as fieldname
from tablename
There is a statement called IFNULL, which takes all the input values and returns the first non NULL value.
example:
select IFNULL(column, 1) FROM table;
http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_ifnull
An UPDATE statement is needed to update data in a table. You cannot use the SELECT statement to do so.