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 '25) AND CASE WHEN properties_loc3.id_loc3 IS NOT NULL THEN properties_loc3.id...' at line 47