You can use AND and OR statements together to connect conditions. Use parentheses to indicate which conditions you want checked first. The conditions inside the parentheses are checked first, and then the conditions outside the parentheses.
If you do not use parentheses, NOT is applied before AND, and AND is applied before OR.
For example, when you run this query:
SELECT NAME, ID, DEPT FROM Q.STAFF WHERE (JOB='SALES' AND COMM > 1200) OR YEARS > 10
QMF Displays this report:
+--------------------------------------------------------------------------------+ | NAME ID DEPT | | --------- ------ ------ | | KOONITZ 90 42 | | JONES 260 10 | | GRAHAM 310 66 | | EDWARDS 340 84 | +--------------------------------------------------------------------------------+
When you run the same query with the parentheses moved:
SELECT NAME, ID, DEPT FROM Q.STAFF WHERE JOB='SALES' AND (COMM > 1200 OR YEARS > 10)
QMF Displays this report:
+--------------------------------------------------------------------------------+ | NAME ID DEPT | | --------- ------ ------ | | KOONITZ 90 42 | | GRAHAM 310 66 | | EDWARDS 340 84 | +--------------------------------------------------------------------------------+