Dips > Data Processing > Query Data

# Query Example 6

This example demonstrates a more complex query which uses both AND and OR operators, and brackets.

TYPE == joint && (TRAVERSE == 1 || TRAVERSE == 2)

1. Select Query Data from the toolbar or the Analysis menu.

2. Create the Expression TYPE == joint.

3. Select the Expression button.

4. Select the AND button.

5. Select the left bracket " ( " button.

6. Create the Expression TRAVERSE == 1

7. Select the Expression button.

8. Select the OR button.

9. Create the Expression TRAVERSE == 2

10. Select the Expression button.

11. Select the right bracket " ) " button.

12. Select OK.

For the example.dip file, this query should create a new file with 21 rows. Note:

- All entries in the TYPE column are "joint"

- All entries in the TRAVERSE column are either 1 OR 2

When creating more complex queries such as this, the user should be extra careful with the use of the AND and OR operators, and brackets, to make sure that the query they create will perform the intended search. It is possible to create a valid query which does not carry out the desired search. For example, if the brackets are removed in this example, the query will behave quite differently:

TYPE == joint && TRAVERSE == 1 || TRAVERSE == 2

This query will find all rows with TYPE = joint AND Traverse = 1, and ANY row with Traverse = 2. Similarly, the query:

TRAVERSE == 1 || TRAVERSE == 2 && TYPE == joint

will find all rows with TYPE = joint AND Traverse = 2, and ANY row with Traverse = 1 (since the AND operator takes precedence over the OR operator). However, the query:

(TRAVERSE == 1 || TRAVERSE == 2) && TYPE == joint

will give identical results to the original query, since we are simply reversing expressions on either side of the AND operator.