To link conditions with OR and give them precedence over conditions linked with AND, you must repeat the AND condition for each OR condition.
For example, imagine that you want to find all employees who have been with the company more than five years and those who have lower-level jobs or are retired. This query requires three conditions, a single condition linked to two additional conditions with AND:
The following procedure illustrates how to create this type of query in the Grid pane.
To combine conditions when OR has precedence
job_lvl
and status
columns, enter values as shown here:
Entering the values shown in the grid above produces the following WHERE clause in the statement in the SQL pane:
WHERE (job_lvl = 100) OR (status = 'R')
hire_date
column and applies to both OR conditions, enter values as shown here:
Entering the values shown in the grid above produces the following WHERE clause in the statement in the SQL pane:
WHERE (job_lvl = 100) AND
(hire_date < '01/01/90' ) OR
(status = 'R') AND
(hire_date < '01/01/91' )
Tip You can repeat an AND condition by adding it once, and then using the Cut and Paste commands from the Edit menu to repeat it for other OR conditions.
The WHERE clause created by the Query Designer is equivalent to the following WHERE clause, which uses parentheses to specify the precedence of OR over AND:
WHERE (job_lvl = 100 OR status = 'R') AND
(hire_date < '01/01/91')
Note If you enter the search conditions in the format shown immediately above in the SQL pane, but then make a change to the query in the Diagram or Grid panes, the Query Designer recreates the SQL statement to match the form with the AND condition explicitly distributed to both OR conditions.