3

I have encountered a weird problem in a MySQL query. This following query is returning me 0 result whereas there are many rows which should be returned. the query is

SELECT DISTINCT SKU, EAN, URL, CID 
  FROM tab_comp_data 
 WHERE status =''

And in many rows there are NULL values in STATUS column but it returns me no rows.

I have tried some other way round.

SELECT DISTINCT SKU, EAN, URL, CID 
  FROM tab_comp_data 
 WHERE status <>'INACT'

this also returns me no rows.

P.S. the STATUS column can only be NULL or 'INACT'

Mureinik
  • 297,002
  • 52
  • 306
  • 350
user3305327
  • 897
  • 4
  • 18
  • 34

5 Answers5

2

I you want to query for NULL values, you should use the IS NULL operator.

So, your query should look like:

SELECT DISTINCT SKU, EAN, URL, CID 
  FROM tab_comp_data
 WHERE status IS NULL
Oscar Pérez
  • 4,377
  • 1
  • 17
  • 36
1

if the value of status is null you have to use is null. That is different from =''

select DISTINCT SKU, EAN, URL, CID from tab_comp_data WHERE status is null
Jens
  • 67,715
  • 15
  • 98
  • 113
1

null is not a value - it's a lack thereof. As such, it cannot be evaluated with the equality (=) or inequality (<>) operators. Instead, it should be checked explicitly with the is operator:

SELECT DISTINCT sku, ean, url, cid 
FROM   tab_comp_data 
WHERE  status IS NULL
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

Try to use is NULL

select DISTINCT SKU, EAN, URL, CID from tab_comp_data WHERE status is NULL
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0
SELECT DISTINCT SKU, EAN, URL, CID 
  FROM tab_comp_data 
 WHERE status IS NULL

Use is null , instead of =''

Vidhi
  • 397
  • 1
  • 5
  • 17