sqlt-sqlwhere-clause

Filter out codes under certain conditions


I need to filter out codes beginning with 45XXX except code that equals 45003

using a where clause:

Select * from table where code NOT IN ('45%') 

will filter out all codes beginning with 45 including 45003 which I still want to include

Is there an easy way to do this?


Solution

  • You could add an OR condition which whitelists the code 45003

    SELECT *
    FROM yourTable
    WHERE code NOT LIKE '45%' OR code = '45003';