Question:
I have a table in a MySQL database that has 5 fields. This would be a model query:
select * from myTable where campo1= 4 and campo2=1 and campo3 =7.
However, field3 can have a null value and I would need to select or exclude combinations that involve this value.
Example1:
select * from myTable where campo1= 4 and campo2=1 and campo3 = null.
Example2:
select * from myTable where campo1= 4 and campo2=1 and campo3 <> null.
The problem is that these two examples don't work. I've tried using "null"
and 'null'
but I can't select.
Any idea?
Answer:
In case campo3 = null
and you don't want to show it:
select * from myTable where campo1= 4 and campo2=1 where campo3 is not null
In case you want to show only when campo3<>null
:
select * from myTable where campo1= 4 and campo2=1 where campo3 is null