Answers.Body: <p>There are also Custom Searches which allow for AND / OR statements. Under the Search pull-down go to the last item "Custom Search".</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-16T19:39:19.880Z
Answers.LastActivityDate: 2016-09-16T19:39:19.880Z
Answers.UserDisplayName: Nina Gonzalez
Answers.Body: <p>The best way to do what you want is to :</p>
  
  <ul>
  <li>create a smart group for (X OR Y OR Z) using search builder</li>
  <li>create a smart group for (C OR D) using search builder</li>
  <li>use search builder to combine all the criteria using Contact -> Group -> '=' -> (the group you have created)</li>
  </ul>
  
  <p>I agree it's pretty tedious... but someone will have to re-work the search builder to allow the logic you want. It's not a simple task.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-14T16:03:00.167Z
Answers.LastActivityDate: 2016-09-14T16:03:00.167Z
Answers.UserDisplayName: samuelsov
Answers.Body: <p>As well as the excellent answers already given, I thought I'd introduce <a href="https://en.wikipedia.org/wiki/De_Morgan%27s_laws" rel="nofollow">De Morgan's Laws</a>.</p>
  
  <p>In short, you can do everything you need to through the interface as is :) </p>
  
  <p>There's also scope to rework it to use <a href="http://querybuilder.js.org/" rel="nofollow">http://querybuilder.js.org/</a> if you've a need. It's more featureful.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-28T12:29:58.087Z
Answers.LastActivityDate: 2016-09-28T12:29:58.087Z
Answers.UserDisplayName: JohnFF
Answers.Body: <p>Re your question "2.Is there some way to search (within CiviCRM with all the benefits and options for search results) as per my second example?" </p>
  
  <p>check out the API Explorer - go to Support -> Developer -> API Explorer. </p>
  
  <p>Not an ideal solution but it should work.  </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-14T16:44:49.870Z
Answers.LastActivityDate: 2016-09-14T16:44:49.870Z
Answers.UserDisplayName: Joe McLaughlin
Body: <p>Search Builder in CiviCRM allows groups of AND statements to be connected by OR statements, but not the other way around.</p>
  
  <p>That is, I can perform a search like:</p>
  
  <p>(X AND Y AND Z) OR (A AND B AND C)</p>
  
  <p>but not:</p>
  
  <p>(X OR Y OR Z) AND A AND B AND (C OR D).</p>
  
  <p>If I want to do the latter, I have to rewrite the entire query for each of the elements in the OR statements.  That gets pretty tedious pretty quickly.</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li><p>Why is it like this?</p></li>
  <li><p>Is there some way to search (within CiviCRM with all the benefits and options for search results) as per my second example?</p></li>
  </ol>
  
  <p>Thanks,
  Lewis</p>
  
Tags: <search-results><search-builder>
Title: How to perform searches with groups of OR statements joined by AND statements
ThreadText: # How to perform searches with groups of OR statements joined by AND statements
  
  (Asked by: username_0 on 2016-09-06)
  
  Search Builder in CiviCRM allows groups of AND statements to be connected by OR statements, but not the other way around.
  
  That is, I can perform a search like:
  
  (X AND Y AND Z) OR (A AND B AND C)
  
  but not:
  
  (X OR Y OR Z) AND A AND B AND (C OR D).
  
  If I want to do the latter, I have to rewrite the entire query for each of the elements in the OR statements. That gets pretty tedious pretty quickly.
  
  My questions are:
  
  1. Why is it like this?
  2. Is there some way to search (within CiviCRM with all the benefits and options for search results) as per my second example?
  
  Thanks,
  username_0
  
  **Tags:** search-results, search-builder
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_1 on 2016-09-16. Score: 1
  
  There are also Custom Searches which allow for AND / OR statements. Under the Search pull-down go to the last item "Custom Search".
  
  
  ---
  
  ### Answer by username_2 on 2016-09-14. Score: 1
  
  The best way to do what you want is to :
  
  * create a smart group for (X OR Y OR Z) using search builder
  * create a smart group for (C OR D) using search builder
  * use search builder to combine all the criteria using Contact -> Group -> '=' -> (the group you have created)
  
  I agree it's pretty tedious... but someone will have to re-work the search builder to allow the logic you want. It's not a simple task.
  
  
  ---
  
  ### Answer by username_3 on 2016-09-28. Score: 1
  
  As well as the excellent answers already given, I thought I'd introduce [De Morgan's Laws](https://en.wikipedia.org/wiki/De_Morgan%27s_laws).
  
  In short, you can do everything you need to through the interface as is :)
  
  There's also scope to rework it to use <http://querybuilder.js.org/> if you've a need. It's more featureful.
  
  
  ---
  
  ### Answer by username_4 on 2016-09-14. Score: 0
  
  Re your question "2.Is there some way to search (within CiviCRM with all the benefits and options for search results) as per my second example?"
  
  check out the API Explorer - go to Support -> Developer -> API Explorer.
  
  Not an ideal solution but it should work.
  
  
  ---
  
  