Search code examples
sqldb2

DB2 Select where not equal to string that is NULL


I have COLUMN1 CHAR(1) in MYTABLE where all rows are NULL and here is my sql query:

SELECT COLUMN1 FROM MYTABLE WHERE COLUMN1 != 'A'

it returns nothing because all rows have NULL in COLUMN1. I suppose it should return everything. How do I make it work? I don't wanna use

COALESCE(NULLIF(COLUMN1, ''), '*')

because it slows down the query. Is there any other alternatives?


Solution

  • If you really want NULLs, then why not

    SELECT COLUMN1 FROM MYTABLE WHERE (COLUMN1 != 'A' OR COLUMN1 IS NULL)
    

    ???