where clause using multiple conditions

52 Views Asked by At
Code1 | Code2 | Code3
----------------------
101| 102  | null 
101| null | null
102| 104  | null 

The above is the table called DiagCodes

Select * From Where

Where condition should check all the three columns Code1, Code2 and Code3.

Result: return the rows that has only the codes IN (101, 102)

So, where condition should return the first and second rows only Third row shouldn't be returned because it has 104 code.

How do I write the where clause to check this condition?

1

There are 1 best solutions below

0
On

I'd expect something like this to work:

select * from table
where
(Code1 is null or Code1 in (101, 102)) and
(Code2 is null or Code2 in (101, 102)) and
(Code3 is null or Code3 in (101, 102))