modified sql where logic to use not equal to improve performance