InterBase Quick Start: Part IV - Logical Operators
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.
Finding Rows that Match Multiple Conditions
When AND appears between search conditions, both conditions must be true for a row to be retrieved. For example, execute this query to find employees in a particular department who 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'
- It should return two rows, one each for employees Parker and Johnson.
Finding Rows that Match at Least One Condition
Use OR between search conditions where you want to retrieve rows that match at least one of the conditions.
- Click the Previous Query
button to display your last query. Change AND to OR and execute the new query. Notice that the results are dramatically different; the query returns 25 rows.
- As a more likely example of the OR operator, execute the following query to find customers who are in either Japan or Hong Kong:
SELECT customer, cust_no, country FROM Customer
WHERE country = 'Japan' OR country = 'Hong Kong'
- The result set should look like this: