InterBase Quick Start: Part IV - Logical Operators
From InterBase
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, 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:
Finding 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.
- Modify the previous query, change
AND
toOR
and execute the query. Notice that the results are dramatically different; the query now returns 25 rows. - As a more likely example of the
OR
operator, execute the following query to find customers who are either inJapan
orHong Kong
:
SELECT customer,
cust_no,
country
FROM Customer
WHERE country = 'Japan'
OR country = 'Hong Kong'
The image below shows the expected result: