Reduce repetition in database queries