Do not append the query if there is no such.
Otherwise it appends 'null' at the end.