You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '25) AND CASE WHEN properties_loc3.id_loc3 IS NOT NULL THEN properties_loc3.id_lo' at line 47