SQL/MX Quick Start (G06.24+, H06.03+)
Stating Conditions for Selecting Data
HP NonStop SQL/MX Quick Start—523724-002
3-3
Specifying More Than One Condition
Specifying More Than One Condition
You can use the logical operators AND and OR to connect two conditions. Notice that
the AND operator is more restrictive because both conditions must be true. The OR
operator requires that only one condition be true.
Using AND or OR
Suppose you want to specify more than one condition in the WHERE clause. For
example, you might want to limit the selection of rows, depending on conditions, for
two or more columns.
Example
Display rows satisfying two conditions. The part description is a printer, and the price is
less than $500:
SELECT PARTNUM, PARTDESC, PRICE
FROM PARTS
WHERE PARTDESC LIKE '%PRINTER%' AND PRICE < 500;
The selected rows are:
PARTNUM PARTDESC PRICE
------- ------------------ ------------
2402 LASER PRINTER,T1 350.00
6603 PRINTER CONTROLLER 45.00
--- 2 row(s) selected.
Example
Display rows where the part description is either a laser printer or a graphic printer, and
the price is less than 4500:
SELECT PARTNUM, PARTDESC, PRICE
FROM PARTS
WHERE (PARTDESC LIKE '%LASER%'
OR PARTDESC LIKE '%GRAPHIC P%')
AND PRICE < 4500;
Operator Example Meaning
AND PARTDESC LIKE '%PRINTER%' AND PRICE
< 500
If values in a row satisfy
both of the conditions, the
row appears in the result.
OR PARTNUM < 3000 OR PARTNUM = 7102 If values in a row satisfy
either of the conditions, the
row appears in the result.