Answers.Body: <p>I'm not sure you can do that in one query only but I might be wrong.</p>
  <p>Using two queries, you could do the following:</p>
  <pre><code>{# Fetch users from the group you don't want to display #}
  {% set usersToExclude = craft
      .users()
      .group('groupToExclude')
      .ids() %}
  
  {# Built an array of ids to exclude adding 'not' to it #}
  {% set exclusionList = ['not'] | merge(usersToExclude) %}
  
  {# Fetch your users excluding the one found above #}
  {% set vnp_users = craft
      .users()
      .group('groupYouWant')
      .id(exclusionList).all() %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-29T13:19:34.467Z
Answers.Text: Thanks Oli, though it would be nice if the group() method could take values to match as well as values to exclude.
Answers.UserDisplayName: user10961
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-29T13:12:04.873Z
Answers.LastActivityDate: 2020-07-29T13:12:04.873Z
Answers.UserDisplayName: Oli
Body: <p>Please could you advise on how to filter a user query, so that users from Group A are included, but not if they are also in Group B?</p>
  <pre><code>{% set vnp_users = craft.users
      .group(['groupA', 'not groupB'])
      .orderBy('field desc')
      .all() %}
  </code></pre>
  
Tags: <users><search><filter>
Title: Filter users: in group AND not in other group
ThreadText: # Filter users: in group AND not in other group
  
  (Asked by: username_0 on 2020-07-29)
  
  Please could you advise on how to filter a user query, so that users from Group A are included, but not if they are also in Group B?
  
  ```
  {% set vnp_users = craft.users
      .group(['groupA', 'not groupB'])
      .orderBy('field desc')
      .all() %}
  
  ```
  
  **Tags:** users, search, filter
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-07-29. Score: 1 | Accepted answer
  
  I'm not sure you can do that in one query only but I might be wrong.
  
  Using two queries, you could do the following:
  
  ```
  {# Fetch users from the group you don't want to display #}
  {% set usersToExclude = craft
      .users()
      .group('groupToExclude')
      .ids() %}
  
  {# Built an array of ids to exclude adding 'not' to it #}
  {% set exclusionList = ['not'] | merge(usersToExclude) %}
  
  {# Fetch your users excluding the one found above #}
  {% set vnp_users = craft
      .users()
      .group('groupYouWant')
      .id(exclusionList).all() %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks Oli, though it would be nice if the group() method could take values to match as well as values to exclude.  
  
  ---
  
  