Emil Rowland
Emil Rowland

Reputation: 558

Mysql change null value to 0

I have this SQL statement for my mysql database.

SELECT MAX(customer_ID) AS high_customer_ID FROM `customers`.`customers` WHERE our_customer_ID=1;

but whene ther is no customer_ID with our_customer_ID = 1 then the statment return null but I want it to return 0 how do i do that.

Upvotes: 1

Views: 184

Answers (1)

Mureinik
Mureinik

Reputation: 312259

You could use the coalesce function to assign a default value in case of a null:

SELECT COALESCE(MAX(customer_ID), 0) AS high_customer_ID 
FROM   `customers`.`customers`
WHERE  our_customer_id = 1;

Upvotes: 3

Related Questions