1.6.1 Example 1: Retrieve customers who purchased products during a period
Retrieve the customer ID (USERID), product code (PUR-CODE), and date of purchase (PUR-DATE) from the sales history table (SALESLIST) for customers who purchased products between September 4, 2011 and September 5, 2011.
- Table to search
- Specification example
-
SELECT "USERID","PUR-CODE","PUR-DATE" FROM "SALESLIST" WHERE "PUR-DATE" BETWEEN DATE'2011-09-04' AND DATE'2011-09-05'
- Retrieval results
- Note
-
A BETWEEN predicate could instead be rewritten using AND conditions. For example, the SELECT statement below, which uses an AND condition, gives the same retrieval results as the specification example above, which uses a BETWEEN predicate.
For details about AND conditions, see 1.5 Retrieving data with search conditions specified.
SELECT "USERID","PUR-CODE","PUR-DATE" FROM "SALESLIST" WHERE "PUR-DATE">=DATE'2011-09-04' AND "PUR-DATE"<=DATE'2011-09-05'