write function for subset query