# Boolean logic for select query assistance

**URL:** <https://community.spicecrm.io/t/boolean-logic-for-select-query-assistance/326>\
**Category:** KReporter\
**Created:** [August 6, 2018, 4:30pm UTC](https://community.spicecrm.io/t/boolean-logic-for-select-query-assistance/326 "2018-08-06T16:30:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FibreCRM\_Simon](https://avatars.discourse-cdn.com/v4/letter/f/f07891/32.png) [@FibreCRM\_Simon](https://community.spicecrm.io/u/FibreCRM_Simon)\
**Post date:** [August 6, 2018, 4:30pm UTC](https://community.spicecrm.io/t/boolean-logic-for-select-query-assistance/326/1 "2018-08-06T16:30:41Z")

</div>

I’m trying to construct a selection criteria as follows

Select where  
Type = x and WTotal \<\> 0  
OR  
Type = x and YTotal \<\> 0

Type should be user choice at runtime.

I have added TYPE to the Root node and created two sub nodes each containing their respective Total \<\> 0

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/spicecrm/original/1X/62ef6c12cae69a415d5c1c34839e249dff5b9b7d.png)

I’m getting confused when to use the AND or the OR

I dont want to add the TYPE field to each sub node because if I do the runtime choice of Type is duplicated.

Hope this makes sense.

---

<div class="post-metadata">

**Author:** ![maretval](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@maretval](https://community.spicecrm.io/u/maretval)\
**Post date:** [August 7, 2018, 9:54pm UTC](https://community.spicecrm.io/t/boolean-logic-for-select-query-assistance/326/2 "2018-08-07T21:54:43Z")

</div>

Simon, I added missing paragraph about this in KReporter documentation:  
[https://spicecrm.gitbooks.io/kreporter-4-x/content/basics/backend/select.html](https://spicecrm.gitbooks.io/kreporter-4-x/content/basics/backend/select.html)

For your report drag your field “type” into select as usual.  
Group root (always there per default) has TYPE AND. This means that any field or group in root level will be concatenated with AND in where clause.

Add a group “W OR Y” (name it as you like) under root. Click OK.  
Then select TYPE OR for this group. All fields dragged into this group will be concatenated with OR in where clause. Drag your fields an configure their settings (operator, value, editable…)

---

<div class="post-metadata">

**Author:** ![FibreCRM\_Simon](https://avatars.discourse-cdn.com/v4/letter/f/f07891/32.png) [@FibreCRM\_Simon](https://community.spicecrm.io/u/FibreCRM_Simon)\
**Post date:** [August 10, 2018, 10:01am UTC](https://community.spicecrm.io/t/boolean-logic-for-select-query-assistance/326/3 "2018-08-10T10:01:58Z")

</div>

Thanks. That explains it and it works nicely.
