MySQL lookup if data is NULL

I need to put Case in Select to check if the Data that I am adding to my view adds NULL, in which case I want it to just enter zero or not.

+4
source share
3 answers

Do you mean something like this?

SELECT IF(`field` IS NULL, 0, `field`)... 

There is also "IFNULL ()":

 SELECT IFNULL(`field`, 0)... 
+12
source
 select coalesce(field, 0) as 'field' from v; 

( doc )

+7
source

When creating a table, just add NOT NULL to the column description, e.g.

CREATE TABLE ( ID INT NOT NULL default '0' );

Then, if no data is specified for the field, it is set to the default value of 0, which will be retrieved when the SELECT query is run.

+2
source

All Articles