db2

Where not in multiple columns

Filter out multiple combinations of values

Lets say you want to filter a query by two columns, but only certain combinations of those columns. For example, it’s OK to have account 60400 with reference JE, but you cannot have account 60400 with reference ED, but you can have account 60500 with reference ED.

select * from schema.table where (acct, ref) not in
( values
  (60400, 'ED'),
  (60600, 'ED'),
  (60701, 'ED'),
  (70400, 'ED'),
  (70500, 'ED'),
  (70600, 'ED'),
  (80800, 'ED')
);

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow