Reputation: 188
I need an sql command that would select all rows that don't contain a certain number.
What I have:
Select * from table
Where (col1 != 1 or col2 != 1 or col3 != 1)
The problem is this does not select any rows that have either of the columns empty. All 3 columns are integer type.
Upvotes: 1
Views: 216
Reputation: 121604
Use is distinct from
instead of !=
for nullable columns:
select *
from my_table
where (
col1 is distinct from 1
or col2 is distinct from 1
or col3 is distinct from 1)
Upvotes: 1