1.7.1 Example 1: Retrieve customers who purchased product code P001 or P003
Retrieve the customer ID (USERID), product code (PUR-CODE), and date of purchase (PUR-DATE) from the sales history table (SALESLIST) of customers who purchased products with product code P001 or P003 on or after September 5, 2011.
- Table to search
- Specification example
-
SELECT "USERID","PUR-CODE","PUR-DATE" FROM "SALESLIST" WHERE "PUR-CODE" IN ('P001','P003') AND "PUR-DATE">=DATE'2011-09-05'
- Retrieval results
- Note
-
An IN predicate could be rewritten using OR conditions. For example, the SELECT statement below, which uses an OR condition, gives the same retrieval results as the specification example above, which uses an IN predicate.
For details about OR conditions, see 1.5 Retrieving data with search conditions specified.
SELECT "USERID","PUR-CODE","PUR-DATE" FROM "SALESLIST" WHERE ("PUR-CODE"='P001' OR "PUR-CODE"='P003') AND "PUR-DATE">=DATE'2011-09-05'