Fix SQL used to get last sequence number during updating indexes