Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't zero date when compared to null, null?

Tags:

date

null

mysql

  1. SELECT NULL; prints

    <null>

  2. SELECT CAST('0000-00-00' AS DATE); prints

    <null>

  3. SELECT NULL IS NULL; prints

    1

  4. SELECT CAST('0000-00-00' AS DATE) IS NULL; prints

    0

Why isn't the result of the 4th statement 1?

Tested using DataGrip while connecting to MySQL 5.7.17 on windows. enter image description here


2 Answers

Because the 2. isn't true:

SELECT CAST('0000-00-00' AS DATE); prints

0000-00-00

It doesn't print

NULL

enter image description here

like image 69
kiks73 Avatar answered Jul 18 '26 10:07

kiks73


4th statement show the result 0000-00-00

In mysql Only null is null. Everything else is not, so that it returns 1

Updated Result

like image 24
iamsankalp89 Avatar answered Jul 18 '26 10:07

iamsankalp89