First please read the article in my signature about posting these types of questions to the forum. After you do that I could make sure that the answer is correct. Without the necessary information the following where statement should get you what you want:where type not in ('aa', 'cc')
and type <> = 'g2'
and code = 3
and (table2.start_date is null
or table2.end_date is null
or table2.program_id is null)
Instead of all of the nulls you could use union all for each of the "is null" statements.