InterBase Quick Start: Part IV - Logical Operators

From InterBase
Jump to: navigation, search

Go Up to InterBase Quick Start: Part IV - Using the WHERE Clause


You can specify multiple search conditions in a WHERE clause by combining them with the logical operators AND or OR.

Image 025.jpgFinding Rows that Match Multiple Conditions

When AND appears between search conditions, the result must meet both conditions to be retrieved. For example, execute the following query to find employees from the department 623 which were hired after January 1, 1992:

SELECT dept_no,
       last_name,
       first_name,
       hire_date
FROM   Employee
WHERE  dept_no = 623
       AND hire_date > '01-Jan-1992'

The image below shows the expected result:

TutorialWhere16.png

Image 025.jpgFinding Rows That Match at Least One Condition

Use OR between search conditions when you want to retrieve rows that match at least one of the conditions.

  1. Modify the previous query, change AND to OR and execute the query. Notice that the results are dramatically different; the query now returns 25 rows.
  2. As a more likely example of the OR operator, execute the following query to find customers who are either in Japan or Hong Kong:
SELECT customer,
       cust_no,
       country
FROM   Customer
WHERE  country = 'Japan'
        OR country = 'Hong Kong'

The image below shows the expected result:

TutorialWhere17.png

Advance To: