Answers.Body: <p>Since sql is probably your best bet, the sql is pretty straight forward.  </p>
  
  <pre><code>SELECT c.display_name, 
         g.name, 
         count(*)
  FROM   civicrm_group_contact gc,
         civicrm_contact c,
         civicrm_group g
  where  gc.contact_id = c.id
  and    gc.group_id = g.id
  and    gc.status = 'Added'
  group by 1
  having count(*) = 1
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-28T06:06:45.403Z
Answers.LastActivityDate: 2015-05-28T06:06:45.403Z
Answers.UserDisplayName: Paul-Tahoe
Answers.Body: <p>If you're trying to count the number of groups each contact is in (and select only those with a single group) then to SQL you shall go!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-27T05:14:06.070Z
Answers.Text: yes, but your solution makes the assumption that all contacts belong to one or more groups
Answers.UserDisplayName: Donald Lobo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-27T19:24:35.010Z
Answers.Text: I edited my answer down following Lobo's comment.  Its not reasonable (although it might actually be possible) to use the Custom Search Include/Exclude to complete this task.
Answers.UserDisplayName: Eliot Mason
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-27T04:57:49.883Z
Answers.LastActivityDate: 2015-05-27T06:36:12.297Z
Answers.LastEditDate: 2015-05-27T06:36:12.297Z
Answers.UserDisplayName: Eliot Mason
Answers.Body: <p>I think you'll have to model this as a custom search (i.e. embed your sql query in a custom search). Not sure if your description includes smart groups, in which case the problem is a bit more complicated.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-26T19:19:05.677Z
Answers.LastActivityDate: 2015-05-26T19:19:05.677Z
Answers.UserDisplayName: Donald Lobo
Body: <p>i could write a sql query but is there a way to do this search from the UI? </p>
  
Tags: <search><groups>
Title: Find Contacts who are in one and only one group?
ThreadText: # Find Contacts who are in one and only one group?
  
  (Asked by: username_0 on 2015-05-26)
  
  i could write a sql query but is there a way to do this search from the UI?
  
  **Tags:** search, groups
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2015-05-28. Score: 2
  
  Since sql is probably your best bet, the sql is pretty straight forward.
  
  ```
  SELECT c.display_name, 
         g.name, 
         count(*)
  FROM   civicrm_group_contact gc,
         civicrm_contact c,
         civicrm_group g
  where  gc.contact_id = c.id
  and    gc.group_id = g.id
  and    gc.status = 'Added'
  group by 1
  having count(*) = 1
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2015-05-27. Score: 1
  
  If you're trying to count the number of groups each contact is in (and select only those with a single group) then to SQL you shall go!
  
  > **Comments:**
  > **username_3**: yes, but your solution makes the assumption that all contacts belong to one or more groups  
  > **username_2**: I edited my answer down following username_3's comment.  Its not reasonable (although it might actually be possible) to use the Custom Search Include/Exclude to complete this task.  
  
  ---
  
  ### Answer by username_3 on 2015-05-26. Score: 0
  
  I think you'll have to model this as a custom search (i.e. embed your sql query in a custom search). Not sure if your description includes smart groups, in which case the problem is a bit more complicated.
  
  
  ---
  
  