tonfry
tonfry

Reputation: 13

MySQL SELECT Statement, changing one value within a column

I'm running a report using SELECT and want to change all NULL values within a column to a specific value in the output. All non-null values should remain untouched.

The null values exist because of an outer join. The column does not exist in all tables, but in the output I want a single value to appear instead of NULL.

Here is non-working SQL to illustrate what I am trying to do.

SELECT number, letter IF number = null THEN 0 END IF FROM... and so on.

Upvotes: 1

Views: 39

Answers (3)

osama yaccoub
osama yaccoub

Reputation: 1866

SELECT letter , IF(number is null, 0, number) as number FROM .....

Upvotes: 0

Rodney Salcedo
Rodney Salcedo

Reputation: 1254

Something like this:

SELECT number, letter, ifnull(number,0) 
FROM table

Upvotes: 1

Ahmad Hammoud
Ahmad Hammoud

Reputation: 701

Check out isNull statement, it might help

http://www.w3schools.com/sql/sql_isnull.asp

Upvotes: 0

Related Questions