WHERE

The WHERE clause has two purposes:

  • To specify record selection criteria.

  • To show how two database tables are joined.

When WHERE is used to specify record selection criteria, it includes a search condition in order to determine which records (rows of data) are to be retrieved. For example:

SELECT
     MYTABLE.'SALESPERSON',
     MYTABLE.'SALESTOTAL'
FROM
     'MYTABLE' MYTABLE
WHERE
     MYTABLE.'SALESTOTAL' < 10000.00

When WHERE is used to specify how two tables are linked, an SQL join operator sits between the two table names. See Linking options.

The following is an example of the WHERE clause joining two tables:

SELECT
     CUSTOMER.'CUST_ID',
     CUSTOMER.'CUST_NAME',
     ORDERS.'AMOUNT'
FROM
     'CUSTOMER' CUSTOMER,
     'ORDERS' ORDERS
WHERE
     CUSTOMER.'CUST_ID' = ORDERS.'CUST_ID'