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
  • 277,661
  • 50
  • 283
  • 320
user3305327
  • 884
  • 4
  • 16
  • 33

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,257
  • 1
  • 16
  • 33
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
  • 63,364
  • 15
  • 92
  • 104
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
  • 277,661
  • 50
  • 283
  • 320
0

Try to use is NULL

select DISTINCT SKU, EAN, URL, CID from tab_comp_data WHERE status is NULL
Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319
0
SELECT DISTINCT SKU, EAN, URL, CID 
  FROM tab_comp_data 
 WHERE status IS NULL

Use is null , instead of =''

Vidhi
  • 387
  • 1
  • 5
  • 17