Fix empty reference while query result is empty