Combine the AND and OR Conditions
Last updated 8/04/2022
Combine the AND and OR Conditions in Five
Criteria can be a combination of AND and OR clauses. Combining the two enables you to perform complex filtering. AND conditions will return rows matching all the specified conditions, while OR conditions will perform the opposite and only retrieve rows that match either conditions.
WHERE Condition_1
AND; Condition_2
...
OR; Condition_4
Create a Query with an AND and OR Condition
Select Menus in the menu.
Click the Add Item button in the list app bar.
Type a title in the Title field.
Click in the Query field to open the Table and Fields Designer.
- Click the Add Table button.
- Select a table.
Click outside of the Table Selector dialog box to close the window.
Select the table and drag to the desired position on the Designer.
Double click the field names required for the query.
In field one, type a condition in the Criteria field.
In field two, type a condition in the Criteria field.
Click the Add Or button.
- In the new row, type an
OR
condition in a Criteria field.
> 1000
= 'Brisbane'
= 'Aspley'
This AND OR
example will return all patients in the Brisbane suburb that have a patient number greater than 1000, or, all patients in the Aspley suburb.
The AND
and OR
conditions can be set for any field that makes logical sense in the Query Builder.
- Click the Save button in the Table and Fields Designer app bar.
- Click the Fields tab.
- Click the Save button in the form app bar.
Ensure to click the Fields tab to have all your query fields saved before committing the form.
Add an AND and OR Condition with Multiple Tables
Select Menus in the menu.
Click the Add Item button in the list app bar.
Type a title in the Title field.
Click in the Query field to open the Table and Fields Designer.
- Click the Add Table button.
Select a table.
Select table two.
Click outside the Table Selector dialog box to close the window.
Select each table and drag to the desired position on the Designer.
In table one, double click the field names required for the query.
In table two, double click the field names required for the query.
In table one, type a condition in the Criteria field for a field.
< 1000
This WHERE
statement will return all patients that have a patient number less than 1000. Because the first name, last name, suburb, date, time, and details fields are included in the query, these are also included in the result set.
In table two, type a condition in the Criteria field for a field.
Click the Add Or button.
< 1000
> '12:00PM'
This AND
statement will return all patients that have a patient number less than 1000 and an appointment after 12:00 PM. Because the first name, last name, suburb, date, and details fields are included in the query, these are also included in the result set.
Five will automatically create the JOIN
between these two tables.
You will notice Five has prefixed all fields with their table name, for example, Patient.Details. This is required to eliminate any ambiguity as to which field is being referenced, as the same field name may exist in both of the tables.
- In the new row, type an
OR
condition in a Criteria field.
< 1000
> '12:00 PM'
= 'Brisbne'
This AND OR
statement will return all patients that have a patient number less than 1000 and have an appointment after 12:00 PM or in the Brisbane suburb. Because the first name, last name, date, and details fields are included in the query, these are also included in the result set.
You can create as many AND
and OR
combinations across multiple tables that are required for your result set.
- Click the Save button in the Table and Fields Designer app bar.
- Click the Fields tab.
- Click the Save button in the form app bar.