add FIRST_BY, LAST_BY functions