Simulating an if condition in the WHERE clause of an SQL query