1

Scenario: I have a table with duplicate data. One of the columns of this table is ddate, if it is empty/null I want to select that row (and remove it). But for some reason, I cannot find the null rows with a direct query.

Issue: When I run the following query (1):

select
    `ddate`, 
    count(1) as `nb`
from instrument_nt
group by `ddate`;

I get the number of rows where ddate is NULL and where it has other values. But when I run query (2):

select count(*) from instrument_nt where `ddate` =  Null;

or

select * from instrument_nt where `ddate` =  NULL;

My query result is either 0 or empty.

Question: What is the difference between those two queries (1 and 2)? How can I properly delete the data that has null/missing dates?

D-Shih
  • 44,943
  • 6
  • 31
  • 51
DGMS89
  • 1,507
  • 6
  • 29
  • 60

4 Answers4

2

NULL mean unknow it's a value.

If you want to get NULL row you need to use IS NULL instead of eqaul NULL

select count(*) from instrument_nt where `ddate` IS  Null;

What is the difference between those two queries (1 and 2)? How can I properly delete the data that has null/missing dates?

(1)

select count(*) from instrument_nt where `ddate` IS  Null;

you will get the amount ddate is NULL from instrument_nt table.

(2)

select * from instrument_nt where `ddate` IS NULL;

you will get a result set which ddate is NULL;

D-Shih
  • 44,943
  • 6
  • 31
  • 51
1

Every null is defined to be different from every other null. Thus, equality to null is always false. See, for example, here, which describes this so-called "three value problem".

For this third class of value, you want to use IS, as in IS NULL or IS NOT NULL.

bishop
  • 37,830
  • 11
  • 104
  • 139
1

use the keyword IS NULL to check the null values in tables

For example:

select * from instrument_nt where `ddate` IS NULL;
Murtaza Hussain
  • 3,851
  • 24
  • 30
0

MySQL null checks use the IS operator instead of =.

Your query should look like this: select * from instrument_nt whereddateIS NULL;

bLind
  • 47
  • 4