Answers.Body: <p>I figured it out in a roundabout way.</p>
  <p><code>orWhere</code> is just an OR join on other <code>orWhere</code> statements.</p>
  <p>this collection of orWhere statements is then AND joined to the query.</p>
  <p>so in my example I needed to do the following</p>
  <pre><code>{% set Query = craft.entries(queryParams) %}
  {% set Query = Query.orWhere(['between', '`content`.`field_fieldNumber`', &quot;1&quot;, &quot;300&quot; ]) %}
  {% set Query = Query.orWhere('`content`.`field_fieldNumber IS NULL') %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-27T00:55:44.553Z
Answers.LastActivityDate: 2021-07-27T00:55:44.553Z
Answers.UserDisplayName: Mark Lloyd
Body: <p>I've been attempting to create an entry query that queries the same custom field twice.</p>
  <p>Basically I want to check if a custom field is between 2 numbers OR if it is empty.
  Currently I'm using this to determine if the field is in range</p>
  <pre><code>{fieldNumber: ['and', '&gt;=' ~ InputLow, '&lt;=' ~ InputHigh] }
  </code></pre>
  <p>I cannot for the life of me work out how to create an additional OR for <code>fieldNumber</code>in the same query.</p>
  <p>I've looked into the Yii <code>orWhere</code> option, but it's separating them with an <code>AND</code> for some reason - I've tried the following as a test</p>
  <pre><code>{% set Query = craft.entries(queryParams) %}
  {% set Query = Query.orWhere(['between', '`content`.`field_fieldNumber`', &quot;#{1}&quot;, &quot;#{300}&quot; ]) %}
  </code></pre>
  <p>it produced the following SQL</p>
  <pre><code> AND (`content`.`field_fieldNumber` BETWEEN 1 AND 300) AND ((`content`.`field_fieldNumber` &gt;= '58') AND (`content`.`field_fieldNumber` &lt;= '62'))...
  </code></pre>
  <p>Ultimately I want a query that will produce something like the below, but I cannot for the life of me work out how to do it.</p>
  <pre><code> AND (`content`.`field_fieldNumber` = null) OR ((`content`.`field_fieldNumber` &gt;= '58') AND (`content`.`field_fieldNumber` &lt;= '62'))...
  </code></pre>
  <p>Has anyone got any ideas, or can anyone point me in the right direction?</p>
  <p>Much appreciated.</p>
  
Tags: <entry><query>
Title: 'and' & 'or' in the same entry query
ThreadText: # 'and' & 'or' in the same entry query
  
  (Asked by: username_0 on 2021-07-24)
  
  I've been attempting to create an entry query that queries the same custom field twice.
  
  Basically I want to check if a custom field is between 2 numbers OR if it is empty.
  Currently I'm using this to determine if the field is in range
  
  ```
  {fieldNumber: ['and', '>=' ~ InputLow, '<=' ~ InputHigh] }
  
  ```
  
  I cannot for the life of me work out how to create an additional OR for `fieldNumber`in the same query.
  
  I've looked into the Yii `orWhere` option, but it's separating them with an `AND` for some reason - I've tried the following as a test
  
  ```
  {% set Query = craft.entries(queryParams) %}
  {% set Query = Query.orWhere(['between', '`content`.`field_fieldNumber`', "#{1}", "#{300}" ]) %}
  
  ```
  
  it produced the following SQL
  
  ```
   AND (`content`.`field_fieldNumber` BETWEEN 1 AND 300) AND ((`content`.`field_fieldNumber` >= '58') AND (`content`.`field_fieldNumber` <= '62'))...
  
  ```
  
  Ultimately I want a query that will produce something like the below, but I cannot for the life of me work out how to do it.
  
  ```
   AND (`content`.`field_fieldNumber` = null) OR ((`content`.`field_fieldNumber` >= '58') AND (`content`.`field_fieldNumber` <= '62'))...
  
  ```
  
  Has anyone got any ideas, or can anyone point me in the right direction?
  
  Much appreciated.
  
  **Tags:** entry, query
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-07-27. Score: 2
  
  I figured it out in a roundabout way.
  
  `orWhere` is just an OR join on other `orWhere` statements.
  
  this collection of orWhere statements is then AND joined to the query.
  
  so in my example I needed to do the following
  
  ```
  {% set Query = craft.entries(queryParams) %}
  {% set Query = Query.orWhere(['between', '`content`.`field_fieldNumber`', "1", "300" ]) %}
  {% set Query = Query.orWhere('`content`.`field_fieldNumber IS NULL') %}
  
  ```
  
  
  ---
  
  