Krizzle
Krizzle

Reputation: 21

How to set up independent queries within a single query

I need to query a table for null values but on different fields. I have been setting up my queries independently and running them one at a time to view my results.

EX:

Query 1:

select * from TABLE1 where FIELD1 is null and FIELD2 is NOT null

Query 2:

Select * from TABLE1 where FIELD6 = 'YES' and FIELD2 is null

Query 3:

select * from TABLE1 where FIELD4 = 'OUTSIDE' and FIELD7 is not null

Is there a way to set up a single query which will allow me retrieve data from a single table but run queries where the conditions are different?

Upvotes: 0

Views: 71

Answers (1)

Bruno Portugal
Bruno Portugal

Reputation: 96

It looks like you could use the or operator:

select * from TABLE1 
    where (FIELD1 is null and FIELD2 is NOT null) 
    or (FIELD6 = 'YES' and FIELD2 is null) 
    or (FIELD4 = 'OUTSIDE' and FIELD7 is not null)

Upvotes: 2

Related Questions