Update sql query for #711