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