Corrected issue with where logic in select_statement